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