annotate src/gtkspell.c @ 1601:32846c6207f2

[gaim-migrate @ 1611] small notes on how tabbing works committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 16 Mar 2001 22:43:14 +0000
parents d33bf6548543
children 60b3fd819cce
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. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 #define BUFSIZE 1024
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 static void error_print(const char *fmt, ...) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 va_list ap;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 va_start(ap, fmt);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 fprintf(stderr, "gtkspell: ");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 vfprintf(stderr, fmt, ap);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 va_end(ap);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 /* functions to interface with pipe */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 static void writetext(char *text) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 write(fd_write[1], text, strlen(text));
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 static int readpipe(char *buf, int bufsize) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 int len;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 len = read(fd_read[0], buf, bufsize-1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 if (len < 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 error_print("read: %s\n", strerror(errno));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 } else if (len == 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 error_print("pipe closed.\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 } else if (len == bufsize-1) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 error_print("buffer overflowed?\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 buf[len] = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 return len;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 static int readline(char *buf) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 return readpipe(buf, BUFSIZE);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 static int readresponse(char *buf) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 int len;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 len = readpipe(buf, BUFSIZE);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 /* all ispell responses of any reasonable length should end in \n\n.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 * depending on the speed of the spell checker, this may require more
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 * reading. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 if (len >= 2 && (buf[len-1] != '\n' || buf[len-2] != '\n')) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 len += readpipe(buf+len, BUFSIZE-len);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 /* now we can remove all of the the trailing newlines. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 while (len > 0 && buf[len-1] == '\n')
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 buf[--len] = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 return len;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 void gtkspell_stop() {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 if (gtkspell_running()) {
1415
3dfd2a83fb5e [gaim-migrate @ 1425]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1127
diff changeset
114 kill(spell_pid, SIGHUP);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
115 spell_pid = 0;
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
116 close(fd_read[0]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
117 close(fd_write[1]);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 int gtkspell_start(char *path, char * args[]) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 int fd_error[2];
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 char buf[BUFSIZE];
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 if (gtkspell_running()) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 error_print("gtkspell_start called while already running.\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 gtkspell_stop();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 if (!signal_set_up) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 set_up_signal();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 signal_set_up = 1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 pipe(fd_write);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 pipe(fd_read);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 pipe(fd_error);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 spell_pid = fork();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 if (spell_pid < 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 error_print("fork: %s\n", strerror(errno));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 } else if (spell_pid == 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 dup2(fd_write[0], 0);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
145 close(fd_write[0]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
146 close(fd_write[1]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
147
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 dup2(fd_read[1], 1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 close(fd_read[0]);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
150 close(fd_read[1]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
151
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
152 dup2(fd_error[1], 2);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 close(fd_error[0]);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
154 close(fd_error[1]);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 if (path == NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 if (execvp(args[0], args) < 0)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 error_print("execvp('%s'): %s\n", args[0], strerror(errno));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 if (execv(path, args) < 0)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 error_print("execv('%s'): %s\n", path, strerror(errno));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 /* if we get here, we failed.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 * send some text on the pipe to indicate status.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 */
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
166 write(0, "!", 1); /* stdout _is_ the pipe. */
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 _exit(0);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 /* there are at least two ways to fail:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 * - the exec() can fail
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172 * - the exec() can succeed, but the program can dump the help screen
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 * we must check for both.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 fd_set rfds;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 struct timeval tv;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
178 close(fd_write[0]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
179 close(fd_read[1]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
180
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 FD_ZERO(&rfds);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 FD_SET(fd_error[0], &rfds);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 FD_SET(fd_read[0], &rfds);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 tv.tv_sec = 2;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 tv.tv_usec = 0;
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
186
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 if (select(MAX(fd_error[0], fd_read[0])+1,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 &rfds, NULL, NULL, &tv) < 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 /* FIXME: is this needed? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 error_print("Timed out waiting for spell command.\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 gtkspell_stop();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 if (FD_ISSET(fd_error[0], &rfds)) { /* stderr readable? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 error_print("Spell command printed on stderr -- probably failed.\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 gtkspell_stop();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 return -1;
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
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
201 /* we're done with stderr, now. */
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
202 close(fd_error[0]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
203 close(fd_error[1]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
204
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 /* otherwise, fd_read[0] is set. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 readline(buf);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 /* ispell should print something like this:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 * @(#) International Ispell Version 3.1.20 10/10/95
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 * if it doesn't, it's an error. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 if (buf[0] != '@') {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212 gtkspell_stop();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 /* put ispell into terse mode.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 * this makes it not respond on correctly spelled words. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219 sprintf(buf, "!\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220 writetext(buf);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221 return 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
224 static GList* misspelled_suggest(char *word) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225 char buf[BUFSIZE];
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
226 char *newword;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
227 GList *l = NULL;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 int count;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 sprintf(buf, "^%s\n", word); /* guard against ispell control chars */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231 writetext(buf);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232 readresponse(buf);
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 switch (buf[0]) { /* first char is ispell command. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235 case 0: /* no response: word is ok. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236 return NULL;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 case '&': /* misspelled, with suggestions */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 /* & <orig> <count> <ofs>: <miss>, <miss>, <guess>, ... */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239 strtok(buf, " "); /* & */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 newword = strtok(NULL, " "); /* orig */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 l = g_list_append(l, g_strdup(newword));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 newword = strtok(NULL, " "); /* count */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 count = atoi(newword);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 strtok(NULL, " "); /* ofs: */
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 while ((newword = strtok(NULL, ",")) != NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247 int len = strlen(newword);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
248 if (newword[len-1] == ' ' || newword[len-1] == '\n')
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249 newword[len-1] = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 if (count == 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
251 g_list_append(l, NULL); /* signal the "suggestions" */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
253 /* add it to the list, skipping the initial space. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
254 l = g_list_append(l,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255 g_strdup(newword[0] == ' ' ? newword+1 : newword));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
256
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257 count--;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259 return l;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261 case '#': /* misspelled, no suggestions */
1467
7f7857c5036e [gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1415
diff changeset
262 case '?': /* ispell is guessing. */
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 /* # <orig> <ofs> */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
264 strtok(buf, " "); /* & */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
265 newword = strtok(NULL, " "); /* orig */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
266 l = g_list_append(l, g_strdup(newword));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267 return l;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
268 default:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269 error_print("Unsupported spell command '%c'.\n"
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
270 "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
271 error_print("Input [%s]\nOutput [%s]\n", word, buf);
7f7857c5036e [gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1415
diff changeset
272
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274 return NULL;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
275 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
277 static int misspelled_test(char *word) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
278 char buf[BUFSIZE];
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
279 sprintf(buf, "^%s\n", word); /* guard against ispell control chars */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
280 writetext(buf);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
281 readresponse(buf);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
282
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
283 if (buf[0] == 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284 return 0;
1467
7f7857c5036e [gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1415
diff changeset
285 } else if (buf[0] == '&' || buf[0] == '#' || buf[0] == '?') {
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
286 return 1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
287 }
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 error_print("Unsupported spell command '%c'.\n"
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
290 "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
291 error_print("Input [%s]\nOutput [%s]\n", word, buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
292 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
293 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
294
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
295 static gboolean iswordsep(char c) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
296 return !isalpha(c) && c != '\'';
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299 static gboolean get_word_from_pos(GtkText* gtktext, int pos, char* buf,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300 int *pstart, int *pend) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
301 gint start, end;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 if (iswordsep(GTK_TEXT_INDEX(gtktext, pos))) return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 for (start = pos; start >= 0; --start) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 if (iswordsep(GTK_TEXT_INDEX(gtktext, start))) break;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
308 start++;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310 for (end = pos; end <= gtk_text_get_length(gtktext); end++) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311 if (iswordsep(GTK_TEXT_INDEX(gtktext, end))) break;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
312 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314 if (buf) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315 for (pos = start; pos < end; pos++)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316 buf[pos-start] = GTK_TEXT_INDEX(gtktext, pos);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
317 buf[pos-start] = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
318 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
320 if (pstart) *pstart = start;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
321 if (pend) *pend = end;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
322
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
323 return TRUE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
324 }
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 static gboolean get_curword(GtkText* gtktext, char* buf,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
327 int *pstart, int *pend) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328 int pos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
329 return get_word_from_pos(gtktext, pos, buf, pstart, pend);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
330 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
331
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332 static void change_color(GtkText *gtktext,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333 int start, int end, GdkColor *color) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334 char *newtext = gtk_editable_get_chars(GTK_EDITABLE(gtktext), start, end);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
335 gtk_text_freeze(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
336 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
337 GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
338
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339 gtk_text_set_point(gtktext, start);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
340 gtk_text_forward_delete(gtktext, end-start);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
341
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342 if (newtext && end-start > 0)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343 gtk_text_insert(gtktext, NULL, color, NULL, newtext, end-start);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
344
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
346 GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
347 gtk_text_thaw(gtktext);
1415
3dfd2a83fb5e [gaim-migrate @ 1425]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1127
diff changeset
348 g_free(newtext);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349 }
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 static gboolean check_at(GtkText *gtktext, int from_pos) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352 int start, end;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
353 char buf[BUFSIZE];
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
355 if (!get_word_from_pos(gtktext, from_pos, buf, &start, &end)) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
356 return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
357 }
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 if (misspelled_test(buf)) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
360 if (highlight.pixel == 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
361 /* add an entry for the highlight in the color map. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
362 GdkColormap *gc = gtk_widget_get_colormap(GTK_WIDGET(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
363 gdk_colormap_alloc_color(gc, &highlight, FALSE, TRUE);;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
364 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
365 change_color(gtktext, start, end, &highlight);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
366 return TRUE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
367 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
368 change_color(gtktext, start, end,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
369 &(GTK_WIDGET(gtktext)->style->fg[0]));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
370 return FALSE;
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 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
374 void gtkspell_check_all(GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
375 guint origpos;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
376 guint pos = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
377 guint len;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
378 float adj_value;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
379
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
380 if (!gtkspell_running()) return;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
381
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
382 len = gtk_text_get_length(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
383
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
384 adj_value = gtktext->vadj->value;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
385 gtk_text_freeze(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
386 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
387 while (pos < len) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
388 while (pos < len && iswordsep(GTK_TEXT_INDEX(gtktext, pos)))
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
389 pos++;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
390 while (pos < len && !iswordsep(GTK_TEXT_INDEX(gtktext, pos)))
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
391 pos++;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
392 if (pos > 0)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
393 check_at(gtktext, pos-1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
394 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
395 gtk_text_thaw(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
396 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399 static void entry_insert_cb(GtkText *gtktext,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400 gchar *newtext, guint len, guint *ppos, gpointer d) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
401 int origpos;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
402
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
403 if (!gtkspell_running()) return;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
405 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 GTK_SIGNAL_FUNC(entry_insert_cb),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
407 NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
408 gtk_text_insert(GTK_TEXT(gtktext), NULL,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409 &(GTK_WIDGET(gtktext)->style->fg[0]), NULL, newtext, len);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
410 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411 GTK_SIGNAL_FUNC(entry_insert_cb),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
412 NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
413 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "insert-text");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414 *ppos += len;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
416 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
418 if (iswordsep(newtext[0])) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
419 /* did we just end a word? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
420 if (*ppos >= 2) check_at(gtktext, *ppos-2);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
421
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
422 /* did we just split a word? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
423 if (*ppos < gtk_text_get_length(gtktext))
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
424 check_at(gtktext, *ppos+1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
426 /* 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
427 * common case.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
428 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
429 if (*ppos < gtk_text_get_length(gtktext) &&
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
430 !iswordsep(GTK_TEXT_INDEX(gtktext, *ppos)))
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 check_at(gtktext, *ppos-1);
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
434 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
435 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);
1117
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438 static void entry_delete_cb(GtkText *gtktext,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
439 gint start, gint end, gpointer d) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440 int origpos;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
441
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
442 if (!gtkspell_running()) return;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
443
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
444 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
445 check_at(gtktext, start-1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
446 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
447 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
448 /* this is to *UNDO* the selection, in case they were holding shift
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
449 * while hitting backspace. */
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 replace_word(GtkWidget *w, gpointer d) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
453 int start, end;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
454 char *newword;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455 char buf[BUFSIZE];
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
456
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
457 /* we don't save their position,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
458 * because the cursor is moved by the click. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
460 gtk_text_freeze(GTK_TEXT(d));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), &newword);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463 get_curword(GTK_TEXT(d), buf, &start, &end);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465 gtk_text_set_point(GTK_TEXT(d), end);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 gtk_text_backward_delete(GTK_TEXT(d), end-start);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 gtk_text_insert(GTK_TEXT(d), NULL, NULL, NULL, newword, strlen(newword));
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 gtk_text_thaw(GTK_TEXT(d));
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
472 static GtkMenu *make_menu(GList *l, GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
473 GtkWidget *menu, *item;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
474 char *caption;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475 menu = gtk_menu_new(); {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
476 caption = g_strdup_printf("Not in dictionary: %s", (char*)l->data);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
477 item = gtk_menu_item_new_with_label(caption);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
478 /* 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
479 * the menu titles in the GNOME panel... unfortunately, the GNOME
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480 * panel creates their own custom widget to do this! */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
481 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
482 gtk_menu_append(GTK_MENU(menu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
484 item = gtk_menu_item_new();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
486 gtk_menu_append(GTK_MENU(menu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
487
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488 l = l->next;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
489 if (l == NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490 item = gtk_menu_item_new_with_label("(no suggestions)");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
491 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
492 gtk_menu_append(GTK_MENU(menu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
493 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
494 GtkWidget *curmenu = menu;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
495 int count = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
496 do {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
497 if (l->data == NULL && l->next != NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
498 count = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
499 curmenu = gtk_menu_new();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
500 item = gtk_menu_item_new_with_label("Other Possibilities...");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
501 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
502 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
503 gtk_menu_append(GTK_MENU(curmenu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
504 l = l->next;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
505 } else if (count > MENUCOUNT) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
506 count -= MENUCOUNT;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
507 item = gtk_menu_item_new_with_label("More...");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
508 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
509 gtk_menu_append(GTK_MENU(curmenu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
510 curmenu = gtk_menu_new();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
511 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
512 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
513 item = gtk_menu_item_new_with_label((char*)l->data);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
514 gtk_signal_connect(GTK_OBJECT(item), "activate",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
515 GTK_SIGNAL_FUNC(replace_word), gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
516 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
517 gtk_menu_append(GTK_MENU(curmenu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
518 count++;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 } while ((l = l->next) != NULL);
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 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 return GTK_MENU(menu);
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
525 static void popup_menu(GtkText *gtktext, GdkEventButton *eb) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
526 char buf[BUFSIZE];
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 GList *list, *l;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
529 get_curword(gtktext, buf, NULL, NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
530
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531 list = misspelled_suggest(buf);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
532 if (list != NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 gtk_menu_popup(make_menu(list, gtktext), NULL, NULL, NULL, NULL,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
534 eb->button, eb->time);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
535 for (l = list; l != NULL; l = l->next)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
536 g_free(l->data);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
537 g_list_free(list);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
538 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
539 }
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 /* ok, this is pretty wacky:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
542 * 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
543 * 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
544 * weird selection modifiers.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
545 *
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
546 * 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
547 * HACK HACK HACK.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
548 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
549 static gint button_press_intercept_cb(GtkText *gtktext, GdkEvent *e, gpointer d) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
550 GdkEventButton *eb;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
551 gboolean retval;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
552
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
553 if (!gtkspell_running()) return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
554
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
555 if (e->type != GDK_BUTTON_PRESS) return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
556 eb = (GdkEventButton*) e;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
557
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
558 if (eb->button != 3) return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
559
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
560 /* forge the leftclick */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
561 eb->button = 1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
562
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
563 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
564 GTK_SIGNAL_FUNC(button_press_intercept_cb), d);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
565 gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "button-press-event",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
566 e, &retval);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
567 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
568 GTK_SIGNAL_FUNC(button_press_intercept_cb), d);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
569 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "button-press-event");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
570
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
571 /* now do the menu wackiness */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
572 popup_menu(gtktext, eb);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
573 return TRUE;
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
576 void gtkspell_uncheck_all(GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
577 int origpos;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
578 char *text;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
579 float adj_value;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
580
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
581 adj_value = gtktext->vadj->value;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
582 gtk_text_freeze(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
583 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
584 text = gtk_editable_get_chars(GTK_EDITABLE(gtktext), 0, -1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
585 gtk_text_set_point(gtktext, 0);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
586 gtk_text_forward_delete(gtktext, gtk_text_get_length(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
587 gtk_text_insert(gtktext, NULL, NULL, NULL, text, strlen(text));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
588 gtk_text_thaw(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
589
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
590 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
591 gtk_adjustment_set_value(gtktext->vadj, adj_value);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
592 }
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 void gtkspell_attach(GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
595 gtk_signal_connect(GTK_OBJECT(gtktext), "insert-text",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
596 GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
597 gtk_signal_connect_after(GTK_OBJECT(gtktext), "delete-text",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
598 GTK_SIGNAL_FUNC(entry_delete_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
599 gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
600 GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
601 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
602
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
603 void gtkspell_detach(GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
604 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
605 GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
606 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
607 GTK_SIGNAL_FUNC(entry_delete_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
608 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
609 GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
610
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
611 gtkspell_uncheck_all(gtktext);
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
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
614 static void sigchld(int param) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
615 if (gtkspell_running() &&
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
616 (waitpid(spell_pid, NULL, WNOHANG) == spell_pid)) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
617 spell_pid = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
618 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
619 /* a default SIGCHLD handler.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
620 * what else to do here? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
621 waitpid(-1, NULL, WNOHANG);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
622 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
623 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
624
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
625 static void set_up_signal() {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
626 struct sigaction sigact;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
627 memset(&sigact, 0, sizeof(struct sigaction));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
628
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
629 sigact.sa_handler = sigchld;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
630 sigaction(SIGCHLD, &sigact, NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
631 }