1 /* gtkpspell - a spell-checking addon for GtkText
2 * Copyright (c) 2000 Evan Martin.
3 * Copyright (c) 2002 Melvin Hadasht.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; If not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Stuphead: (C) 2000,2001 Grigroy Bakunov, Sergey Pinaev
21 * Adapted for Sylpheed (Claws) (c) 2001-2002 by Hiroyuki Yamamoto &
22 * The Sylpheed Claws Team.
23 * Adapted for pspell (c) 2001-2002 Melvin Hadasht
26 #if defined(HAVE_CONFIG_H)
35 #include <sys/types.h>
48 #include <prefs_common.h>
53 #include <gtk/gtkoptionmenu.h>
54 #include <gtk/gtkmenu.h>
55 #include <gtk/gtkmenuitem.h>
56 #include <gdk/gdkkeysyms.h>
62 #include <pspell/pspell.h>
63 /* size of the text buffer used in various word-processing routines. */
66 /* number of suggestions to display on each menu. */
69 /* 'config' must be defined as a 'PspellConfig *' */
70 #define RETURN_FALSE_IF_CONFIG_ERROR() \
71 if (pspell_config_error_number(config) != 0) { \
72 gtkpspellcheckers->error_message = g_strdup(pspell_config_error_message(config)); \
76 #define CONFIG_REPLACE_RETURN_FALSE_IF_FAIL(option, value) { \
77 pspell_config_replace(config, option, value); \
78 RETURN_FALSE_IF_CONFIG_ERROR(); \
81 /******************************************************************************/
83 GtkPspellCheckers *gtkpspellcheckers;
85 /* Error message storage */
86 static void gtkpspell_checkers_error_message(gchar *message);
89 static void entry_insert_cb (GtkSText *gtktext,
93 GtkPspell *gtkpspell);
94 static void entry_delete_cb (GtkSText *gtktext,
97 GtkPspell *gtkpspell);
98 static gint button_press_intercept_cb (GtkSText *gtktext,
100 GtkPspell *gtkpspell);
102 /* Checker creation */
103 static GtkPspeller * gtkpspeller_new (Dictionary *dict);
104 static GtkPspeller * gtkpspeller_real_new (Dictionary *dict);
105 static GtkPspeller * gtkpspeller_delete (GtkPspeller *gtkpspeller);
106 static GtkPspeller * gtkpspeller_real_delete (GtkPspeller *gtkpspeller);
108 /* Checker configuration */
109 static gint set_dictionary (PspellConfig *config,
111 static void set_sug_mode_cb (GtkMenuItem *w,
112 GtkPspell *gtkpspell);
113 static void set_real_sug_mode (GtkPspell *gtkpspell,
114 const char *themode);
116 /* Checker actions */
117 static gboolean check_at (GtkPspell *gtkpspell,
119 static gboolean check_next_prev (GtkPspell *gtkpspell,
121 static GList* misspelled_suggest (GtkPspell *gtkpspell,
123 static void add_word_to_session_cb (GtkWidget *w,
125 static void add_word_to_personal_cb (GtkWidget *w,
127 static void replace_with_create_dialog_cb (GtkWidget *w,
129 static void replace_with_supplied_word_cb (GtkWidget *w,
130 GtkPspell *gtkpspell);
131 static void replace_word_cb (GtkWidget *w,
133 static void replace_real_word (GtkPspell *gtkpspell,
135 static void toggle_check_while_typing_cb (GtkWidget *w,
139 static void popup_menu (GtkPspell *gtkpspell,
141 static GtkMenu* make_sug_menu (GtkPspell *gtkpspell);
142 static void populate_submenu (GtkPspell *gtkpspell,
144 static GtkMenu* make_config_menu (GtkPspell *gtkpspell);
145 static void set_menu_pos (GtkMenu *menu,
149 /* Other menu callbacks */
150 static gboolean cancel_menu_cb (GtkMenuShell *w,
152 static void change_dict_cb (GtkWidget *w,
153 GtkPspell *gtkpspell);
155 /* Misc. helper functions */
156 static void set_point_continue (GtkPspell *gtkpspell);
157 static void continue_check (gpointer *gtkpspell);
158 static gboolean iswordsep (unsigned char c);
159 static guchar get_text_index_whar (GtkPspell *gtkpspell,
161 static gboolean get_word_from_pos (GtkPspell *gtkpspell,
167 static void allocate_color (GtkPspell *gtkpspell,
169 static void change_color (GtkPspell *gtkpspell,
174 static guchar* convert_to_pspell_encoding (const guchar *encoding);
175 static gint compare_dict (Dictionary *a,
177 static void dictionary_delete (Dictionary *dict);
178 static Dictionary * dictionary_dup (const Dictionary *dict);
179 static void free_suggestions_list (GtkPspell *gtkpspell);
180 static void reset_theword_data (GtkPspell *gtkpspell);
181 static void free_checkers (gpointer elt,
183 static gint find_gtkpspeller (gconstpointer aa,
185 static void gtkpspell_alert_dialog (gchar *message);
186 /* gtkspellconfig - only one config per session */
187 GtkPspellConfig * gtkpspellconfig;
189 /******************************************************************************/
191 GtkPspellCheckers * gtkpspell_checkers_new()
193 GtkPspellCheckers *gtkpspellcheckers;
195 gtkpspellcheckers = g_new(GtkPspellCheckers, 1);
197 gtkpspellcheckers->checkers = NULL;
199 gtkpspellcheckers->dictionary_list = NULL;
201 gtkpspellcheckers->error_message = NULL;
203 return gtkpspellcheckers;
206 GtkPspellCheckers *gtkpspell_checkers_delete()
211 if (gtkpspellcheckers == NULL) return NULL;
213 if ((checkers = gtkpspellcheckers->checkers)) {
214 debug_print(_("Pspell: number of running checkers to delete %d\n"),
215 g_slist_length(checkers));
217 g_slist_foreach(checkers, free_checkers, NULL);
218 g_slist_free(checkers);
221 if ((dict_list = gtkpspellcheckers->dictionary_list)) {
222 debug_print(_("Pspell: number of dictionaries to delete %d\n"),
223 g_slist_length(dict_list));
225 gtkpspell_free_dictionary_list(dict_list);
226 gtkpspellcheckers->dictionary_list = NULL;
229 g_free(gtkpspellcheckers->error_message);
234 static void gtkpspell_checkers_error_message (gchar *message)
237 if (gtkpspellcheckers->error_message) {
238 tmp = g_strdup_printf("%s\n%s",
239 gtkpspellcheckers->error_message, message);
241 g_free(gtkpspellcheckers->error_message);
242 gtkpspellcheckers->error_message = tmp;
243 } else gtkpspellcheckers->error_message = message;
246 void gtkpspell_checkers_reset_error()
248 g_return_if_fail(gtkpspellcheckers);
250 g_free(gtkpspellcheckers->error_message);
252 gtkpspellcheckers->error_message = NULL;
255 GtkPspell *gtkpspell_new(const gchar *dictionary,
256 const gchar *encoding,
257 gint misspelled_color,
258 gboolean check_while_typing,
261 Dictionary *dict = g_new0(Dictionary, 1);
262 GtkPspell *gtkpspell;
263 GtkPspeller *gtkpspeller;
265 g_return_val_if_fail(gtktext, NULL);
267 dict->fullname = g_strdup(dictionary);
268 dict->encoding = g_strdup(encoding);
269 gtkpspeller = gtkpspeller_new(dict);
270 dictionary_delete(dict);
275 gtkpspell = g_new(GtkPspell, 1);
277 gtkpspell->gtkpspeller = gtkpspeller;
278 gtkpspell->theword[0] = 0x00;
279 gtkpspell->start_pos = 0;
280 gtkpspell->end_pos = 0;
281 gtkpspell->orig_pos = -1;
282 gtkpspell->end_check_pos = -1;
283 gtkpspell->misspelled = -1;
284 gtkpspell->check_while_typing = check_while_typing;
285 gtkpspell->continue_check = NULL;
286 gtkpspell->config_menu = NULL;
287 gtkpspell->popup_config_menu = NULL;
288 gtkpspell->sug_menu = NULL;
289 gtkpspell->replace_entry = NULL;
290 gtkpspell->gtktext = gtktext;
291 gtkpspell->default_sug_mode = PSPELL_FASTMODE;
292 gtkpspell->max_sug = -1;
293 gtkpspell->suggestions_list = NULL;
295 allocate_color(gtkpspell, misspelled_color);
297 gtk_signal_connect_after(GTK_OBJECT(gtktext), "insert-text",
298 GTK_SIGNAL_FUNC(entry_insert_cb), gtkpspell);
299 gtk_signal_connect_after(GTK_OBJECT(gtktext), "delete-text",
300 GTK_SIGNAL_FUNC(entry_delete_cb), gtkpspell);
301 gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event",
302 GTK_SIGNAL_FUNC(button_press_intercept_cb), gtkpspell);
304 debug_print("Pspell: created gtkpspell %0x\n", gtkpspell);
309 void gtkpspell_delete(GtkPspell * gtkpspell)
313 gtktext = gtkpspell->gtktext;
315 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
316 GTK_SIGNAL_FUNC(entry_insert_cb), gtkpspell);
317 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
318 GTK_SIGNAL_FUNC(entry_delete_cb), gtkpspell);
319 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
320 GTK_SIGNAL_FUNC(button_press_intercept_cb),
323 gtkpspell_uncheck_all(gtkpspell);
325 gtkpspeller_delete(gtkpspell->gtkpspeller);
327 if (gtkpspell->sug_menu)
328 gtk_widget_destroy(gtkpspell->sug_menu);
329 if (gtkpspell->popup_config_menu)
330 gtk_widget_destroy(gtkpspell->popup_config_menu);
331 if (gtkpspell->config_menu)
332 gtk_widget_destroy(gtkpspell->config_menu);
333 if (gtkpspell->suggestions_list)
334 free_suggestions_list(gtkpspell);
336 debug_print("Pspell: deleting gtkpspell %0x\n", gtkpspell);
343 static void entry_insert_cb(GtkSText *gtktext, gchar *newtext,
344 guint len, guint *ppos,
345 GtkPspell * gtkpspell)
347 g_return_if_fail(gtkpspell->gtkpspeller->checker);
349 if (!gtkpspell->check_while_typing)
352 /* We must insert ourself the character to impose the */
353 /* color of the inserted character to be default */
354 /* Never mess with set_insertion when frozen */
355 gtk_stext_freeze(gtktext);
356 gtk_stext_backward_delete(GTK_STEXT(gtktext), len);
357 gtk_stext_insert(GTK_STEXT(gtktext), NULL, NULL, NULL, newtext, len);
358 *ppos = gtk_stext_get_point(GTK_STEXT(gtktext));
360 if (iswordsep(newtext[0])) {
361 /* did we just end a word? */
363 check_at(gtkpspell, *ppos - 2);
365 /* did we just split a word? */
366 if (*ppos < gtk_stext_get_length(gtktext))
367 check_at(gtkpspell, *ppos + 1);
369 /* check as they type, *except* if they're typing at the end (the most
372 if (*ppos < gtk_stext_get_length(gtktext)
373 && !iswordsep(get_text_index_whar(gtkpspell, *ppos)))
374 check_at(gtkpspell, *ppos - 1);
376 gtk_stext_thaw(gtktext);
377 gtk_editable_set_position(GTK_EDITABLE(gtktext), *ppos);
380 static void entry_delete_cb(GtkSText *gtktext, gint start, gint end,
381 GtkPspell *gtkpspell)
385 g_return_if_fail(gtkpspell->gtkpspeller->checker);
387 if (!gtkpspell->check_while_typing)
390 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
392 check_at(gtkpspell, start - 1);
393 check_at(gtkpspell, start);
396 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
397 gtk_stext_set_point(gtktext, origpos);
398 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);
399 /* this is to *UNDO* the selection, in case they were holding shift
400 * while hitting backspace. */
403 /* ok, this is pretty wacky:
404 * we need to let the right-mouse-click go through, so it moves the cursor,
405 * but we *can't* let it go through, because GtkText interprets rightclicks as
406 * weird selection modifiers.
408 * so what do we do? forge rightclicks as leftclicks, then popup the menu.
411 static gint button_press_intercept_cb(GtkSText *gtktext, GdkEvent *e, GtkPspell *gtkpspell)
416 g_return_val_if_fail(gtkpspell->gtkpspeller->checker, FALSE);
418 if (e->type != GDK_BUTTON_PRESS)
420 eb = (GdkEventButton*) e;
425 /* forge the leftclick */
428 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
429 GTK_SIGNAL_FUNC(button_press_intercept_cb),
431 gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "button-press-event",
433 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
434 GTK_SIGNAL_FUNC(button_press_intercept_cb),
436 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "button-press-event");
438 /* now do the menu wackiness */
439 popup_menu(gtkpspell, eb);
440 gtk_grab_remove(GTK_WIDGET(gtktext));
444 /*****************************************************************************/
445 /* Checker creation */
446 static GtkPspeller *gtkpspeller_new(Dictionary *dictionary)
449 GtkPspeller *gtkpspeller = NULL;
450 GtkPspeller *g = g_new0(GtkPspeller, 1);
454 g_return_val_if_fail(gtkpspellcheckers, NULL);
456 g_return_val_if_fail(dictionary, NULL);
458 if (dictionary->fullname == NULL)
459 gtkpspell_checkers_error_message(g_strdup(_("No dictionary selected.")));
461 g_return_val_if_fail(dictionary->fullname, NULL);
463 if (dictionary->dictname == NULL) {
466 tmp = strrchr(dictionary->fullname, G_DIR_SEPARATOR);
469 dictionary->dictname = dictionary->fullname;
471 dictionary->dictname = tmp + 1;
474 dict = dictionary_dup(dictionary);
476 ispell = (strstr2(dict->dictname, "-ispell") != NULL);
478 g->dictionary = dict;
480 exist = g_slist_find_custom(gtkpspellcheckers->checkers, g,
485 if (exist && ispell) {
486 gtkpspeller = (GtkPspeller *) exist->data;
487 dictionary_delete(dict);
489 debug_print(_("Pspell: Using existing ispell checker %0x\n"),
492 if ((gtkpspeller = gtkpspeller_real_new(dict)) != NULL) {
493 gtkpspellcheckers->checkers = g_slist_append(
494 gtkpspellcheckers->checkers,
497 debug_print(_("Pspell: Created a new gtkpspeller %0x\n"),
500 dictionary_delete(dict);
502 debug_print(_("Pspell: Could not create spell checker.\n"));
506 debug_print(_("Pspell: number of existing checkers %d\n"),
507 g_slist_length(gtkpspellcheckers->checkers));
512 static GtkPspeller *gtkpspeller_real_new(Dictionary *dict)
514 GtkPspeller *gtkpspeller;
515 PspellConfig *config;
516 PspellCanHaveError *ret;
518 g_return_val_if_fail(gtkpspellcheckers, NULL);
519 g_return_val_if_fail(dict, NULL);
521 gtkpspeller = g_new(GtkPspeller, 1);
523 gtkpspeller->dictionary = dict;
524 gtkpspeller->sug_mode = PSPELL_FASTMODE;
526 config = new_pspell_config();
528 if (!set_dictionary(config, dict))
531 ret = new_pspell_manager(config);
532 delete_pspell_config(config);
534 if (pspell_error_number(ret) != 0) {
535 gtkpspellcheckers->error_message = g_strdup(pspell_error_message(ret));
537 delete_pspell_can_have_error(ret);
542 gtkpspeller->checker = to_pspell_manager(ret);
543 gtkpspeller->config = pspell_manager_config(gtkpspeller->checker);
544 gtkpspeller->ispell = (strstr2(dict->fullname, "-ispell") != NULL);
549 static GtkPspeller *gtkpspeller_delete(GtkPspeller *gtkpspeller)
551 g_return_val_if_fail(gtkpspellcheckers, NULL);
553 if (gtkpspeller->ispell)
554 debug_print(_("Pspell: Won't remove existing ispell checker %0x.\n"),
557 gtkpspellcheckers->checkers = g_slist_remove(gtkpspellcheckers->checkers,
560 debug_print(_("Pspell: Deleting gtkpspeller %0x.\n"),
563 gtkpspeller_real_delete(gtkpspeller);
566 debug_print(_("Pspell: number of existing checkers %d\n"),
567 g_slist_length(gtkpspellcheckers->checkers));
572 static GtkPspeller *gtkpspeller_real_delete(GtkPspeller *gtkpspeller)
574 g_return_val_if_fail(gtkpspeller, NULL);
575 g_return_val_if_fail(gtkpspeller->checker, NULL);
577 pspell_manager_save_all_word_lists(gtkpspeller->checker);
579 delete_pspell_manager(gtkpspeller->checker);
581 dictionary_delete(gtkpspeller->dictionary);
588 /*****************************************************************************/
589 /* Checker configuration */
591 static gboolean set_dictionary(PspellConfig *config, Dictionary *dict)
593 gchar *language = NULL;
594 gchar *spelling = NULL;
595 gchar *jargon = NULL;
596 gchar *module = NULL;
600 g_return_val_if_fail(config, FALSE);
601 g_return_val_if_fail(dict, FALSE);
603 strncpy(buf, dict->fullname, BUFSIZE-1);
604 buf[BUFSIZE-1] = 0x00;
606 buf[dict->dictname - dict->fullname] = 0x00;
608 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("rem-all-word-list-path", "");
609 debug_print(_("Pspell: removed all paths.\n"));
611 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("add-word-list-path", buf);
612 debug_print(_("Pspell: added path %s.\n"), buf);
614 strncpy(buf, dict->dictname, BUFSIZE-1);
617 if ((module = strrchr(buf, '-')) != NULL) {
620 if ((spelling = strchr(language, '-')) != NULL)
622 if (spelling != module) {
623 if ((end = strchr(spelling, '-')) != NULL) {
626 if (jargon != module)
627 if ((end = strchr(jargon, '-')) != NULL)
640 debug_print(_("Pspell: Language: %s, spelling: %s, jargon: %s, module: %s\n"),
641 language, spelling, jargon, module);
644 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("language-tag", language);
647 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("spelling", spelling);
650 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("jargon", jargon);
653 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("rem-all-module-search-order", "");
654 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("add-module-search-order", module);
657 if (dict->encoding) {
660 pspell_enc = convert_to_pspell_encoding (dict->encoding);
661 pspell_config_replace(config, "encoding", (const char *) pspell_enc);
664 RETURN_FALSE_IF_CONFIG_ERROR();
670 guchar *gtkpspell_get_dict(GtkPspell *gtkpspell)
673 g_return_val_if_fail(gtkpspell->gtkpspeller->config, NULL);
674 g_return_val_if_fail(gtkpspell->gtkpspeller->dictionary, NULL);
676 return g_strdup(gtkpspell->gtkpspeller->dictionary->dictname);
679 guchar *gtkpspell_get_path(GtkPspell *gtkpspell)
684 g_return_val_if_fail(gtkpspell->gtkpspeller->config, NULL);
685 g_return_val_if_fail(gtkpspell->gtkpspeller->dictionary, NULL);
687 dict = gtkpspell->gtkpspeller->dictionary;
688 path = g_strndup(dict->fullname, dict->dictname - dict->fullname);
693 /* set_sug_mode_cb() - Menu callback : Set the suggestion mode */
694 static void set_sug_mode_cb(GtkMenuItem *w, GtkPspell *gtkpspell)
698 if (gtkpspell->gtkpspeller->ispell) return;
700 gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), (gchar **) &themode);
702 set_real_sug_mode(gtkpspell, themode);
704 if (gtkpspell->config_menu)
705 populate_submenu(gtkpspell, gtkpspell->config_menu);
707 static void set_real_sug_mode(GtkPspell *gtkpspell, const char *themode)
710 gint mode = PSPELL_FASTMODE;
711 g_return_if_fail(gtkpspell);
712 g_return_if_fail(gtkpspell->gtkpspeller);
713 g_return_if_fail(themode);
715 if (!strcmp(themode,_("Normal Mode")))
716 mode = PSPELL_NORMALMODE;
717 else if (!strcmp( themode,_("Bad Spellers Mode")))
718 mode = PSPELL_BADSPELLERMODE;
720 result = gtkpspell_set_sug_mode(gtkpspell, mode);
723 debug_print(_("Pspell: error while changing suggestion mode:%s\n"),
724 gtkpspellcheckers->error_message);
725 gtkpspell_checkers_reset_error();
729 /* gtkpspell_set_sug_mode() - Set the suggestion mode */
730 gboolean gtkpspell_set_sug_mode(GtkPspell *gtkpspell, gint themode)
732 PspellConfig *config;
734 g_return_val_if_fail(gtkpspell, FALSE);
735 g_return_val_if_fail(gtkpspell->gtkpspeller, FALSE);
736 g_return_val_if_fail(gtkpspell->gtkpspeller->config, FALSE);
738 debug_print("Pspell: setting sug mode of gtkpspeller %0x to %d\n",
739 gtkpspell->gtkpspeller, themode);
740 config = gtkpspell->gtkpspeller->config;
742 case PSPELL_FASTMODE:
743 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("sug-mode", "fast");
745 case PSPELL_NORMALMODE:
746 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("sug-mode", "normal");
748 case PSPELL_BADSPELLERMODE:
749 CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("sug-mode",
753 gtkpspellcheckers->error_message =
754 g_strdup(_("Unknown suggestion mode."));
758 gtkpspell->gtkpspeller->sug_mode = themode;
759 gtkpspell->default_sug_mode = themode;
764 /* misspelled_suggest() - Create a suggestion list for word */
765 static GList *misspelled_suggest(GtkPspell *gtkpspell, guchar *word)
767 const guchar *newword;
769 const PspellWordList *suggestions;
770 PspellStringEmulation *elements;
772 g_return_val_if_fail(word, NULL);
774 if (!pspell_manager_check(gtkpspell->gtkpspeller->checker, word, -1)) {
775 free_suggestions_list(gtkpspell);
777 suggestions = pspell_manager_suggest(gtkpspell->gtkpspeller->checker,
778 (const char *)word, -1);
779 elements = pspell_word_list_elements(suggestions);
780 list = g_list_append(list, g_strdup(word));
782 while ((newword = pspell_string_emulation_next(elements)) != NULL)
783 list = g_list_append(list, g_strdup(newword));
785 gtkpspell->max_sug = g_list_length(list) - 1;
786 gtkpspell->suggestions_list = list;
791 free_suggestions_list(gtkpspell);
796 /* misspelled_test() - Just test if word is correctly spelled */
797 static int misspelled_test(GtkPspell *gtkpspell, unsigned char *word)
799 return pspell_manager_check(gtkpspell->gtkpspeller->checker, word, -1) ? 0 : 1;
803 static gboolean iswordsep(unsigned char c)
805 return !isalpha(c) && c != '\'';
808 static guchar get_text_index_whar(GtkPspell *gtkpspell, int pos)
813 text = gtk_editable_get_chars(GTK_EDITABLE(gtkpspell->gtktext), pos, pos + 1);
821 /* get_word_from_pos () - return the word pointed to. */
822 /* Handles correctly the quotes. */
823 static gboolean get_word_from_pos(GtkPspell *gtkpspell, gint pos,
824 unsigned char* buf, gint buflen,
825 gint *pstart, gint *pend)
828 /* TODO : when correcting a word into quotes, change the color of */
829 /* the quotes too, as may be they were highlighted before. To do */
830 /* this, we can use two others pointers that points to the whole */
831 /* word including quotes. */
838 gtktext = gtkpspell->gtktext;
839 if (iswordsep(get_text_index_whar(gtkpspell, pos)))
842 /* The apostrophe character is somtimes used for quotes
843 * So include it in the word only if it is not surrounded
844 * by other characters.
847 for (start = pos; start >= 0; --start) {
848 c = get_text_index_whar(gtkpspell, start);
851 if (!isalpha(get_text_index_whar(gtkpspell, start - 1))) {
852 /* start_quote = TRUE; */
857 /* start_quote = TRUE; */
867 for (end = pos; end < gtk_stext_get_length(gtktext); end++) {
868 c = get_text_index_whar(gtkpspell, end);
870 if (end < gtk_stext_get_length(gtktext)) {
871 if (!isalpha(get_text_index_whar(gtkpspell, end + 1))) {
872 /* end_quote = TRUE; */
877 /* end_quote = TRUE; */
892 if (end - start < buflen) {
893 for (pos = start; pos < end; pos++)
894 buf[pos - start] = get_text_index_whar(gtkpspell, pos);
895 buf[pos - start] = 0;
902 static gboolean check_at(GtkPspell *gtkpspell, gint from_pos)
905 unsigned char buf[GTKPSPELLWORDSIZE];
908 g_return_val_if_fail(from_pos >= 0, FALSE);
910 gtktext = gtkpspell->gtktext;
912 if (!get_word_from_pos(gtkpspell, from_pos, buf, sizeof(buf),
916 if (misspelled_test(gtkpspell, buf)) {
917 strncpy(gtkpspell->theword, buf, GTKPSPELLWORDSIZE - 1);
918 gtkpspell->theword[GTKPSPELLWORDSIZE - 1] = 0;
919 gtkpspell->start_pos = start;
920 gtkpspell->end_pos = end;
921 free_suggestions_list(gtkpspell);
923 change_color(gtkpspell, start, end, buf, &(gtkpspell->highlight));
926 change_color(gtkpspell, start, end, buf, NULL);
931 static gboolean check_next_prev(GtkPspell *gtkpspell, gboolean forward)
940 maxpos = gtkpspell->end_check_pos;
948 pos = gtk_editable_get_position(GTK_EDITABLE(gtkpspell->gtktext));
949 gtkpspell->orig_pos = pos;
950 while (iswordsep(get_text_index_whar(gtkpspell, pos)) && pos > minpos && pos <= maxpos)
952 while (!(misspelled = check_at(gtkpspell, pos)) && pos > minpos && pos <= maxpos)
954 while (!iswordsep(get_text_index_whar(gtkpspell, pos)) && pos > minpos && pos <= maxpos)
957 while (iswordsep(get_text_index_whar(gtkpspell, pos)) && pos > minpos && pos <= maxpos)
961 misspelled_suggest(gtkpspell, gtkpspell->theword);
963 gtkpspell->orig_pos = gtkpspell->end_pos;
964 gtk_stext_set_point(GTK_STEXT(gtkpspell->gtktext),
966 gtk_editable_set_position(GTK_EDITABLE(gtkpspell->gtktext),
968 gtk_menu_popup(make_sug_menu(gtkpspell), NULL, NULL,
969 set_menu_pos, gtkpspell, 0, GDK_CURRENT_TIME);
971 reset_theword_data(gtkpspell);
973 gtkpspell_alert_dialog(_("No misspelled word found."));
974 gtk_stext_set_point(GTK_STEXT(gtkpspell->gtktext), gtkpspell->orig_pos);
975 gtk_editable_set_position(GTK_EDITABLE(gtkpspell->gtktext), gtkpspell->orig_pos);
980 void gtkpspell_check_backwards(GtkPspell *gtkpspell)
982 gtkpspell->continue_check = NULL;
983 gtkpspell->end_check_pos = gtk_stext_get_length(GTK_STEXT(gtkpspell->gtktext));
984 check_next_prev(gtkpspell, FALSE);
987 void gtkpspell_check_forwards_go(GtkPspell *gtkpspell)
990 gtkpspell->continue_check = NULL;
991 gtkpspell->end_check_pos = gtk_stext_get_length(GTK_STEXT(gtkpspell->gtktext));
992 check_next_prev(gtkpspell, TRUE);
995 void gtkpspell_check_all(GtkPspell *gtkpspell)
1001 g_return_if_fail(gtkpspell);
1002 g_return_if_fail(gtkpspell->gtktext);
1004 gtktext = (GtkWidget *) gtkpspell->gtktext;
1007 end = gtk_stext_get_length(GTK_STEXT(gtktext));
1009 if (GTK_EDITABLE(gtktext)->has_selection) {
1010 start = GTK_EDITABLE(gtktext)->selection_start_pos;
1011 end = GTK_EDITABLE(gtktext)->selection_end_pos;
1022 gtk_editable_set_position(GTK_EDITABLE(gtktext), start);
1023 gtk_stext_set_point(GTK_STEXT(gtktext), start);
1025 gtkpspell->continue_check = continue_check;
1026 gtkpspell->end_check_pos = end;
1028 gtkpspell->misspelled = check_next_prev(gtkpspell, TRUE);
1032 static void continue_check(gpointer *data)
1034 GtkPspell *gtkpspell = (GtkPspell *) data;
1035 gint pos = gtk_editable_get_position(GTK_EDITABLE(gtkpspell->gtktext));
1037 if (pos < gtkpspell->end_check_pos && gtkpspell->misspelled)
1038 gtkpspell->misspelled = check_next_prev(gtkpspell, TRUE);
1040 gtkpspell->continue_check = NULL;
1044 void gtkpspell_highlight_all(GtkPspell *gtkpspell)
1052 g_return_if_fail(gtkpspell->gtkpspeller->checker);
1054 gtktext = gtkpspell->gtktext;
1056 adj_value = gtktext->vadj->value;
1058 len = gtk_stext_get_length(gtktext);
1060 gtk_stext_freeze(gtktext);
1062 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
1064 /* gtk_editable_set_position(GTK_EDITABLE(gtktext), 0);*/
1068 iswordsep(get_text_index_whar(gtkpspell, pos)))
1071 !iswordsep(get_text_index_whar(gtkpspell, pos)))
1074 check_at(gtkpspell, pos - 1);
1076 gtk_stext_thaw(gtktext);
1077 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
1078 gtk_stext_set_point(GTK_STEXT(gtktext), origpos);
1079 gtk_adjustment_set_value(gtktext->vadj, adj_value);
1080 /*gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);*/
1083 static void replace_with_supplied_word_cb(GtkWidget *w, GtkPspell *gtkpspell)
1085 unsigned char *newword;
1086 GdkEvent *e= (GdkEvent *) gtk_get_current_event();
1088 newword = gtk_editable_get_chars(GTK_EDITABLE(gtkpspell->replace_entry), 0, -1);
1090 if (strcmp(newword, gtkpspell->theword)) {
1091 replace_real_word(gtkpspell, newword);
1093 if ((e->type == GDK_KEY_PRESS &&
1094 ((GdkEventKey *) e)->state & GDK_MOD1_MASK)) {
1095 pspell_manager_store_replacement(gtkpspell->gtkpspeller->checker,
1096 gtkpspell->theword, -1,
1099 gtkpspell->replace_entry = NULL;
1104 set_point_continue(gtkpspell);
1108 static void replace_word_cb(GtkWidget *w, gpointer data)
1110 unsigned char *newword;
1111 GtkPspell *gtkpspell = (GtkPspell *) data;
1112 GdkEvent *e= (GdkEvent *) gtk_get_current_event();
1115 gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), (gchar**) &newword);
1117 replace_real_word(gtkpspell, newword);
1119 if ((e->type == GDK_KEY_PRESS &&
1120 ((GdkEventKey *) e)->state & GDK_MOD1_MASK) ||
1121 (e->type == GDK_BUTTON_RELEASE &&
1122 ((GdkEventButton *) e)->state & GDK_MOD1_MASK)) {
1123 pspell_manager_store_replacement(gtkpspell->gtkpspeller->checker,
1124 gtkpspell->theword, -1,
1128 gtk_menu_shell_deactivate(GTK_MENU_SHELL(w->parent));
1130 set_point_continue(gtkpspell);
1133 static void replace_real_word(GtkPspell *gtkpspell, gchar *newword)
1135 int oldlen, newlen, wordlen;
1138 gint start = gtkpspell->start_pos;
1141 if (!newword) return;
1143 gtktext = gtkpspell->gtktext;
1145 gtk_stext_freeze(GTK_STEXT(gtktext));
1146 origpos = gtkpspell->orig_pos;
1148 oldlen = gtkpspell->end_pos - gtkpspell->start_pos;
1149 wordlen = strlen(gtkpspell->theword);
1151 newlen = strlen(newword); /* FIXME: multybyte characters? */
1153 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
1154 GTK_SIGNAL_FUNC(entry_insert_cb),
1156 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
1157 GTK_SIGNAL_FUNC(entry_delete_cb),
1160 gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "delete-text",
1161 gtkpspell->start_pos, gtkpspell->end_pos);
1162 gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "insert-text",
1163 newword, newlen, &start);
1165 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
1166 GTK_SIGNAL_FUNC(entry_insert_cb),
1168 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
1169 GTK_SIGNAL_FUNC(entry_delete_cb),
1172 /* Put the point and the position where we clicked with the mouse */
1173 /* It seems to be a hack, as I must thaw,freeze,thaw the widget */
1174 /* to let it update correctly the word insertion and then the */
1175 /* point & position position. If not, SEGV after the first replacement */
1176 /* If the new word ends before point, put the point at its end*/
1178 if (origpos - gtkpspell->start_pos < oldlen &&
1179 origpos - gtkpspell->start_pos >= 0) {
1180 /* Original point was in the word. */
1181 /* Let it there unless point is going to be outside of the word */
1182 if (origpos - gtkpspell->start_pos >= newlen) {
1183 pos = gtkpspell->start_pos + newlen;
1186 else if (origpos >= gtkpspell->end_pos) {
1187 /* move the position according to the change of length */
1188 pos = origpos + newlen - oldlen;
1191 gtkpspell->end_pos = gtkpspell->start_pos + strlen(newword); /* FIXME: multibyte characters? */
1193 gtk_stext_thaw(GTK_STEXT(gtktext));
1194 gtk_stext_freeze(GTK_STEXT(gtktext));
1196 if (GTK_STEXT(gtktext)->text_len < pos)
1197 pos = gtk_stext_get_length(GTK_STEXT(gtktext));
1199 gtkpspell->orig_pos = pos;
1201 gtk_editable_set_position(GTK_EDITABLE(gtktext), gtkpspell->orig_pos);
1202 gtk_stext_set_point(GTK_STEXT(gtktext),
1203 gtk_editable_get_position(GTK_EDITABLE(gtktext)));
1205 gtk_stext_thaw(GTK_STEXT(gtktext));
1208 /* Accept this word for this session */
1209 static void add_word_to_session_cb(GtkWidget *w, gpointer data)
1213 GtkPspell *gtkpspell = (GtkPspell *) data;
1214 gtktext = gtkpspell->gtktext;
1216 gtk_stext_freeze(GTK_STEXT(gtktext));
1218 pos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
1220 pspell_manager_add_to_session(gtkpspell->gtkpspeller->checker,
1222 strlen(gtkpspell->theword));
1224 check_at(gtkpspell, gtkpspell->start_pos);
1226 gtk_stext_thaw(gtkpspell->gtktext);
1228 gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
1230 set_point_continue(gtkpspell);
1233 /* add_word_to_personal_cb() - add word to personal dict. */
1234 static void add_word_to_personal_cb(GtkWidget *w, gpointer data)
1237 GtkPspell *gtkpspell = (GtkPspell *) data;
1238 gtktext = gtkpspell->gtktext;
1240 gtk_stext_freeze(GTK_STEXT(gtktext));
1242 pspell_manager_add_to_personal(gtkpspell->gtkpspeller->checker,
1244 strlen(gtkpspell->theword));
1246 check_at(gtkpspell, gtkpspell->start_pos);
1248 gtk_stext_thaw(gtkpspell->gtktext);
1250 gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
1251 set_point_continue(gtkpspell);
1254 static void deactivate_sug_menu_cb(GtkObject *w, gpointer data)
1256 GtkMenuShell *menu_shell = GTK_MENU_SHELL(data);
1257 debug_print("Destroying %0x\n", w);
1258 gtk_menu_shell_deactivate(menu_shell);
1261 static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
1267 GtkWidget *ok_button;
1268 GtkWidget *cancel_button;
1271 GtkPspell *gtkpspell = (GtkPspell *) data;
1273 gdk_window_get_origin((GTK_WIDGET(w)->parent)->window, &xx, &yy);
1275 gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
1277 dialog = gtk_dialog_new();
1278 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
1279 gtk_window_set_title(GTK_WINDOW(dialog),_("Replace unknown word"));
1280 gtk_widget_set_uposition(dialog, xx, yy);
1282 gtk_signal_connect_object(GTK_OBJECT(dialog), "destroy",
1283 GTK_SIGNAL_FUNC(gtk_widget_destroy),
1284 GTK_OBJECT(dialog));
1286 hbox = gtk_hbox_new(FALSE, 0);
1287 gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
1289 thelabel = g_strdup_printf(_("Replace \"%s\" with: "),
1290 gtkpspell->theword);
1291 label = gtk_label_new(thelabel);
1293 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1295 entry = gtk_entry_new();
1296 gtkpspell->replace_entry = entry;
1297 gtk_entry_set_text(GTK_ENTRY(entry), gtkpspell->theword);
1298 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
1299 gtk_signal_connect(GTK_OBJECT(entry), "activate",
1300 GTK_SIGNAL_FUNC(replace_with_supplied_word_cb),
1302 gtk_signal_connect_object(GTK_OBJECT(entry), "activate",
1303 GTK_SIGNAL_FUNC(gtk_widget_destroy),
1304 GTK_OBJECT(dialog));
1305 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
1307 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE,
1309 if (!gtkpspell->gtkpspeller->ispell) {
1310 label = gtk_label_new(_("Holding down MOD1 key while pressing Enter\nwill learn from mistake.\n"));
1311 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
1312 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
1313 gtk_misc_set_padding(GTK_MISC(label), 8, 0);
1314 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label,
1318 hbox = gtk_hbox_new(TRUE, 0);
1320 ok_button = gtk_button_new_with_label(_("OK"));
1321 gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 8);
1322 gtk_signal_connect(GTK_OBJECT(ok_button), "clicked",
1323 GTK_SIGNAL_FUNC(replace_with_supplied_word_cb),
1325 gtk_signal_connect_object(GTK_OBJECT(ok_button), "clicked",
1326 GTK_SIGNAL_FUNC(gtk_widget_destroy),
1327 GTK_OBJECT(dialog));
1329 cancel_button = gtk_button_new_with_label(_("Cancel"));
1330 gtk_box_pack_start(GTK_BOX(hbox), cancel_button, TRUE, TRUE, 8);
1331 gtk_signal_connect_object(GTK_OBJECT(cancel_button), "clicked",
1332 GTK_SIGNAL_FUNC(gtk_widget_destroy),
1333 GTK_OBJECT(dialog));
1335 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), hbox);
1337 gtk_widget_grab_focus(entry);
1339 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
1341 gtk_widget_show_all(dialog);
1344 void gtkpspell_uncheck_all(GtkPspell * gtkpspell)
1351 gtktext = gtkpspell->gtktext;
1353 adj_value = gtktext->vadj->value;
1355 gtk_stext_freeze(gtktext);
1357 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
1359 text = gtk_editable_get_chars(GTK_EDITABLE(gtktext), 0, -1);
1361 gtk_stext_set_point(gtktext, 0);
1362 gtk_stext_forward_delete(gtktext, gtk_stext_get_length(gtktext));
1363 gtk_stext_insert(gtktext, NULL, NULL, NULL, text, strlen(text));
1365 gtk_stext_thaw(gtktext);
1367 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
1368 gtk_stext_set_point(gtktext, origpos);
1369 gtk_adjustment_set_value(gtktext->vadj, adj_value);
1375 static void toggle_check_while_typing_cb(GtkWidget *w, gpointer data)
1377 GtkPspell *gtkpspell = (GtkPspell *) data;
1379 gtkpspell->check_while_typing = gtkpspell->check_while_typing == FALSE;
1380 if (!gtkpspell->check_while_typing)
1381 gtkpspell_uncheck_all(gtkpspell);
1383 if (gtkpspell->config_menu)
1384 populate_submenu(gtkpspell, gtkpspell->config_menu);
1387 static GSList *create_empty_dictionary_list(void)
1389 GSList *list = NULL;
1392 dict = g_new0(Dictionary, 1);
1393 dict->fullname = g_strdup(_("None"));
1394 dict->dictname = dict->fullname;
1395 dict->encoding = NULL;
1396 return g_slist_append(list, dict);
1399 /* gtkpspell_get_dictionary_list() - returns list of dictionary names */
1400 GSList *gtkpspell_get_dictionary_list(const gchar *pspell_path, gint refresh)
1403 gchar *dict_path, *tmp, *prevdir;
1404 gchar tmpname[BUFSIZE];
1409 if (!gtkpspellcheckers)
1410 gtkpspellcheckers = gtkpspell_checkers_new();
1412 if (gtkpspellcheckers->dictionary_list && !refresh)
1413 return gtkpspellcheckers->dictionary_list;
1415 gtkpspell_free_dictionary_list(gtkpspellcheckers->dictionary_list);
1420 #warning TODO: no directory change
1422 dict_path = g_strdup(pspell_path);
1423 prevdir = g_get_current_dir();
1424 if (chdir(dict_path) <0) {
1425 debug_print(_("Pspell: error when searching for dictionaries:\n%s\n"),
1429 gtkpspellcheckers->dictionary_list = create_empty_dictionary_list();
1430 return gtkpspellcheckers->dictionary_list;
1433 debug_print(_("Pspell: checking for dictionaries in %s\n"), dict_path);
1435 if (NULL != (dir = opendir("."))) {
1436 while (NULL != (ent = readdir(dir))) {
1437 /* search for pwli */
1438 if ((NULL != (tmp = strstr2(ent->d_name, ".pwli"))) &&
1440 g_snprintf(tmpname, BUFSIZE, "%s%s",
1441 G_DIR_SEPARATOR_S, ent->d_name);
1442 tmpname[MIN(tmp - ent->d_name + 1, BUFSIZE-1)] = 0x00;
1443 dict = g_new0(Dictionary, 1);
1444 dict->fullname = g_strdup_printf("%s%s",
1447 dict->dictname = strrchr(dict->fullname,
1448 G_DIR_SEPARATOR) + 1;
1449 dict->encoding = NULL;
1450 debug_print(_("Pspell: found dictionary %s %s\n"),
1451 dict->fullname, dict->dictname);
1452 list = g_slist_insert_sorted(list, dict,
1453 (GCompareFunc) compare_dict);
1459 debug_print(_("Pspell: error when searching for dictionaries.\nNo dictionary found.\n(%s)"),
1461 list = create_empty_dictionary_list();
1465 debug_print(_("Pspell: error when searching for dictionaries.\nNo dictionary found."));
1466 list = create_empty_dictionary_list();
1471 gtkpspellcheckers->dictionary_list = list;
1475 void gtkpspell_free_dictionary_list(GSList *list)
1479 for (walk = list; walk != NULL; walk = g_slist_next(walk))
1481 dict = (Dictionary *) walk->data;
1482 dictionary_delete(dict);
1488 static void dictionary_option_menu_item_data_destroy(gpointer data)
1490 Dictionary *dict = (Dictionary *) data;
1493 dictionary_delete(dict);
1497 GtkWidget *gtkpspell_dictionary_option_menu_new(const gchar *pspell_path)
1499 GSList *dict_list, *tmp;
1504 dict_list = gtkpspell_get_dictionary_list(pspell_path, TRUE);
1505 g_return_val_if_fail(dict_list, NULL);
1507 menu = gtk_menu_new();
1509 for (tmp = dict_list; tmp != NULL; tmp = g_slist_next(tmp)) {
1510 dict = (Dictionary *) tmp->data;
1511 item = gtk_menu_item_new_with_label(dict->dictname);
1512 gtk_object_set_data(GTK_OBJECT(item), "dict_name",
1515 gtk_menu_append(GTK_MENU(menu), item);
1516 gtk_widget_show(item);
1519 gtk_widget_show(menu);
1524 gchar *gtkpspell_get_dictionary_menu_active_item(GtkWidget *menu)
1526 GtkWidget *menuitem;
1527 gchar *dict_fullname;
1530 g_return_val_if_fail(GTK_IS_MENU(menu), NULL);
1531 menuitem = gtk_menu_get_active(GTK_MENU(menu));
1532 dict_fullname = (gchar *) gtk_object_get_data(GTK_OBJECT(menuitem), "dict_name");
1533 g_return_val_if_fail(dict_fullname, NULL);
1534 label = g_strdup(dict_fullname);
1539 GtkWidget *gtkpspell_sugmode_option_menu_new(gint sugmode)
1545 menu = gtk_menu_new();
1546 gtk_widget_show(menu);
1548 item = gtk_menu_item_new_with_label(_("Fast Mode"));
1549 gtk_widget_show(item);
1550 gtk_menu_append(GTK_MENU(menu), item);
1551 gtk_object_set_data(GTK_OBJECT(item), "sugmode", GINT_TO_POINTER(PSPELL_FASTMODE));
1553 item = gtk_menu_item_new_with_label(_("Normal Mode"));
1554 gtk_widget_show(item);
1555 gtk_menu_append(GTK_MENU(menu), item);
1556 gtk_object_set_data(GTK_OBJECT(item), "sugmode", GINT_TO_POINTER(PSPELL_NORMALMODE));
1558 item = gtk_menu_item_new_with_label(_("Bad Spellers Mode"));
1559 gtk_widget_show(item);
1560 gtk_menu_append(GTK_MENU(menu), item);
1561 gtk_object_set_data(GTK_OBJECT(item), "sugmode", GINT_TO_POINTER(PSPELL_BADSPELLERMODE));
1566 void gtkpspell_sugmode_option_menu_set(GtkOptionMenu *optmenu, gint sugmode)
1568 g_return_if_fail(GTK_IS_OPTION_MENU(optmenu));
1570 g_return_if_fail(sugmode == PSPELL_FASTMODE ||
1571 sugmode == PSPELL_NORMALMODE ||
1572 sugmode == PSPELL_BADSPELLERMODE);
1574 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), sugmode - 1);
1577 gint gtkpspell_get_sugmode_from_option_menu(GtkOptionMenu *optmenu)
1582 g_return_val_if_fail(GTK_IS_OPTION_MENU(optmenu), -1);
1584 item = gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(optmenu)));
1586 sugmode = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(item), "sugmode"));
1591 #if 0 /* Experimenal */
1592 void gtkpspell_set_primary_dict(GtkPspell *gtkpspell, gchar *dict, gchar *encoding)
1594 g_return_if_fail(gtkpspell);
1595 if (gtkpspell->dict1)
1596 dictionary_delete(gtkpspell->dict1);
1597 gtkpspell->dict1 = g_new(Dictionary, 1);
1598 gtkpspell->dict1->fullname = g_strdup(dict);
1599 gtkpspell->dict1->encoding = g_strdup(encoding);
1602 void gtkpspell_set_secondary_dict(GtkPspell *gtkpspell, gchar *dict, gchar *encoding)
1604 g_return_if_fail(gtkpspell);
1605 if (gtkpspell->dict2)
1606 dictionary_delete(gtkpspell->dict2);
1607 gtkpspell->dict2 = g_new(Dictionary, 1);
1608 gtkpspell->dict2->fullname = g_strdup(dict);
1609 gtkpspell->dict2->encoding = g_strdup(encoding);
1612 gboolean gtkpspell_use_dict(GtkPspell *gtkpspell, Dictionary *dict)
1617 gboolean gtkpspell_use_dictionary(GtkPspell *gtkpspell, gchar *dictpath, gchar *encoding)
1622 g_return_val_if_fail(gtkpspell, FALSE);
1623 g_return_val_if_fail(dict, FALSE);
1624 g_return_val_if_fail(encoding, FALSE);
1626 dict = g_new(Dictionary, 1);
1628 dict->fullname = g_strdup(dictpath);
1629 dict->encoding = NULL; /* To be continued */
1631 retval = gtkpspell_use_dict(gtkpspell, dict);
1633 dictionary_delete(dict);
1639 gboolean gtkpspell_use_primary(GtkPspell *gtkpspell)
1641 g_return_val_if_fail(gtkpspell, FALSE);
1643 return gtkpspell_use_dict(gtkpspell, gtkpspell->dict1);
1646 gboolean gtkpspell_use_secondary(GtkPspell *gtkpspell)
1648 g_return_val_if_fail(gtkpspell, FALSE);
1650 return gtkpspell_use_dict(gtkpspell, gtkpspell->dict2);
1654 /*****************************************************************************/
1656 static void popup_menu(GtkPspell *gtkpspell, GdkEventButton *eb)
1660 gtktext = gtkpspell->gtktext;
1661 gtkpspell->orig_pos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
1663 if (!(eb->state & GDK_SHIFT_MASK)) {
1664 if (check_at(gtkpspell, gtkpspell->orig_pos)) {
1666 gtk_editable_set_position(GTK_EDITABLE(gtktext),
1667 gtkpspell->orig_pos);
1668 gtk_stext_set_point(gtktext, gtkpspell->orig_pos);
1670 if (misspelled_suggest(gtkpspell, gtkpspell->theword)) {
1671 gtk_menu_popup(make_sug_menu(gtkpspell),
1672 NULL, NULL, NULL, NULL,
1673 eb->button, GDK_CURRENT_TIME);
1678 gtk_editable_set_position(GTK_EDITABLE(gtktext),
1679 gtkpspell->orig_pos);
1680 gtk_stext_set_point(gtktext, gtkpspell->orig_pos);
1684 gtk_menu_popup(make_config_menu(gtkpspell),NULL,NULL,NULL,NULL,
1685 eb->button, GDK_CURRENT_TIME);
1688 /* make_sug_menu() - Add menus to accept this word for this session and to add it to
1689 * personal dictionary */
1690 static GtkMenu *make_sug_menu(GtkPspell *gtkpspell)
1692 GtkWidget *menu, *item;
1693 unsigned char *caption;
1695 GList *l = gtkpspell->suggestions_list;
1696 GtkAccelGroup *accel;
1699 gtktext = gtkpspell->gtktext;
1701 accel = gtk_accel_group_new();
1702 menu = gtk_menu_new();
1704 if (gtkpspell->sug_menu)
1705 gtk_widget_destroy(gtkpspell->sug_menu);
1707 gtkpspell->sug_menu = menu;
1709 gtk_signal_connect(GTK_OBJECT(menu), "cancel",
1710 GTK_SIGNAL_FUNC(cancel_menu_cb), gtkpspell);
1712 caption = g_strdup_printf(_("Unknown word: \"%s\""),
1713 (unsigned char*) l->data);
1714 item = gtk_menu_item_new_with_label(caption);
1715 gtk_widget_show(item);
1716 gtk_menu_append(GTK_MENU(menu), item);
1717 gtk_misc_set_alignment(GTK_MISC(GTK_BIN(item)->child), 0.5, 0.5);
1720 item = gtk_menu_item_new();
1721 gtk_widget_show(item);
1722 gtk_menu_append(GTK_MENU(menu), item);
1724 item = gtk_menu_item_new_with_label(_("Accept in this session"));
1725 gtk_widget_show(item);
1726 gtk_menu_append(GTK_MENU(menu), item);
1727 gtk_signal_connect(GTK_OBJECT(item), "activate",
1728 GTK_SIGNAL_FUNC(add_word_to_session_cb),
1730 gtk_widget_add_accelerator(item, "activate", accel, GDK_space, GDK_MOD1_MASK,
1731 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1733 item = gtk_menu_item_new_with_label(_("Add to personal dictionary"));
1734 gtk_widget_show(item);
1735 gtk_menu_append(GTK_MENU(menu), item);
1736 gtk_signal_connect(GTK_OBJECT(item), "activate",
1737 GTK_SIGNAL_FUNC(add_word_to_personal_cb),
1739 gtk_widget_add_accelerator(item, "activate", accel, GDK_Return, GDK_MOD1_MASK,
1740 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1742 item = gtk_menu_item_new_with_label(_("Replace with..."));
1743 gtk_widget_show(item);
1744 gtk_menu_append(GTK_MENU(menu), item);
1745 gtk_signal_connect(GTK_OBJECT(item), "activate",
1746 GTK_SIGNAL_FUNC(replace_with_create_dialog_cb),
1748 gtk_widget_add_accelerator(item, "activate", accel, GDK_R, 0,
1749 GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1751 item = gtk_menu_item_new();
1752 gtk_widget_show(item);
1753 gtk_menu_append(GTK_MENU(menu), item);
1757 item = gtk_menu_item_new_with_label(_("(no suggestions)"));
1758 gtk_widget_show(item);
1759 gtk_menu_append(GTK_MENU(menu), item);
1761 GtkWidget *curmenu = menu;
1765 if (l->data == NULL && l->next != NULL) {
1767 curmenu = gtk_menu_new();
1768 item = gtk_menu_item_new_with_label(_("Others..."));
1769 gtk_widget_show(item);
1770 gtk_menu_append(GTK_MENU(curmenu), item);
1771 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
1774 } else if (count > MENUCOUNT) {
1777 item = gtk_menu_item_new_with_label(_("More..."));
1778 gtk_widget_show(item);
1779 gtk_menu_append(GTK_MENU(curmenu), item);
1781 curmenu = gtk_menu_new();
1782 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
1785 item = gtk_menu_item_new_with_label((unsigned char*)l->data);
1786 gtk_widget_show(item);
1787 gtk_menu_append(GTK_MENU(curmenu), item);
1788 gtk_signal_connect(GTK_OBJECT(item), "activate",
1789 GTK_SIGNAL_FUNC(replace_word_cb), gtkpspell);
1791 if (curmenu == menu && count < MENUCOUNT) {
1792 gtk_widget_add_accelerator(item, "activate",
1797 gtk_widget_add_accelerator(item, "activate",
1806 } while ((l = l->next) != NULL);
1809 gtk_accel_group_attach(accel, GTK_OBJECT(menu));
1810 gtk_accel_group_unref(accel);
1812 return GTK_MENU(menu);
1815 static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu)
1817 GtkWidget *item, *submenu;
1818 GtkPspeller *gtkpspeller = gtkpspell->gtkpspeller;
1820 gint ispell = gtkpspeller->ispell;
1822 if (GTK_MENU_SHELL(menu)->children) {
1823 GList *amenu, *alist;
1824 for (amenu = (GTK_MENU_SHELL(menu)->children); amenu; ) {
1825 alist = amenu->next;
1826 gtk_widget_destroy(GTK_WIDGET(amenu->data));
1831 dictname = g_strdup_printf(_("Dictionary: %s"), gtkpspeller->dictionary->dictname);
1832 item = gtk_menu_item_new_with_label(dictname);
1833 gtk_misc_set_alignment(GTK_MISC(GTK_BIN(item)->child), 0.5, 0.5);
1835 gtk_widget_show(item);
1836 gtk_menu_append(GTK_MENU(menu), item);
1838 item = gtk_menu_item_new();
1839 gtk_widget_show(item);
1840 gtk_menu_append(GTK_MENU(menu), item);
1842 item = gtk_check_menu_item_new_with_label(_("Fast Mode"));
1843 if (ispell || gtkpspell->gtkpspeller->sug_mode == PSPELL_FASTMODE)
1844 gtk_widget_set_sensitive(GTK_WIDGET(item),FALSE);
1845 if (!ispell && gtkpspell->gtkpspeller->sug_mode == PSPELL_FASTMODE)
1846 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),TRUE);
1848 gtk_signal_connect(GTK_OBJECT(item), "activate",
1849 GTK_SIGNAL_FUNC(set_sug_mode_cb),
1851 gtk_widget_show(item);
1852 gtk_menu_append(GTK_MENU(menu), item);
1854 item = gtk_check_menu_item_new_with_label(_("Normal Mode"));
1855 if (ispell || gtkpspell->gtkpspeller->sug_mode == PSPELL_NORMALMODE)
1856 gtk_widget_set_sensitive(GTK_WIDGET(item), FALSE);
1857 if (!ispell && gtkpspell->gtkpspeller->sug_mode == PSPELL_NORMALMODE)
1858 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
1860 gtk_signal_connect(GTK_OBJECT(item), "activate",
1861 GTK_SIGNAL_FUNC(set_sug_mode_cb),
1863 gtk_widget_show(item);
1864 gtk_menu_append(GTK_MENU(menu),item);
1866 item = gtk_check_menu_item_new_with_label(_("Bad Spellers Mode"));
1867 if (ispell || gtkpspell->gtkpspeller->sug_mode == PSPELL_BADSPELLERMODE)
1868 gtk_widget_set_sensitive(GTK_WIDGET(item), FALSE);
1869 if (!ispell && gtkpspell->gtkpspeller->sug_mode == PSPELL_BADSPELLERMODE)
1870 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
1872 gtk_signal_connect(GTK_OBJECT(item), "activate",
1873 GTK_SIGNAL_FUNC(set_sug_mode_cb),
1875 gtk_widget_show(item);
1876 gtk_menu_append(GTK_MENU(menu), item);
1878 item = gtk_menu_item_new();
1879 gtk_widget_show(item);
1880 gtk_menu_append(GTK_MENU(menu), item);
1882 item = gtk_check_menu_item_new_with_label(_("Check while typing"));
1883 if (gtkpspell->check_while_typing)
1884 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
1886 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), FALSE);
1887 gtk_signal_connect(GTK_OBJECT(item), "activate",
1888 GTK_SIGNAL_FUNC(toggle_check_while_typing_cb),
1890 gtk_widget_show(item);
1891 gtk_menu_append(GTK_MENU(menu), item);
1893 item = gtk_menu_item_new();
1894 gtk_widget_show(item);
1895 gtk_menu_append(GTK_MENU(menu), item);
1897 submenu = gtk_menu_new();
1898 item = gtk_menu_item_new_with_label(_("Change dictionary"));
1899 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),submenu);
1900 gtk_widget_show(item);
1901 gtk_menu_append(GTK_MENU(menu), item);
1904 if (gtkpspellcheckers->dictionary_list == NULL)
1905 gtkpspell_get_dictionary_list(prefs_common.pspell_path, FALSE);
1907 GtkWidget * curmenu = submenu;
1911 tmp = gtkpspellcheckers->dictionary_list;
1913 for (tmp = gtkpspellcheckers->dictionary_list; tmp != NULL;
1914 tmp = g_slist_next(tmp)) {
1915 dict = (Dictionary *) tmp->data;
1916 item = gtk_check_menu_item_new_with_label(dict->dictname);
1917 gtk_object_set_data(GTK_OBJECT(item), "dict_name", dict->fullname);
1918 if (strcmp2(dict->fullname, gtkpspell->gtkpspeller->dictionary->fullname))
1919 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), FALSE);
1921 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
1922 gtk_widget_set_sensitive(GTK_WIDGET(item), FALSE);
1924 gtk_signal_connect(GTK_OBJECT(item), "activate",
1925 GTK_SIGNAL_FUNC(change_dict_cb),
1927 gtk_widget_show(item);
1928 gtk_menu_append(GTK_MENU(curmenu), item);
1932 if (count == MENUCOUNT) {
1935 newmenu = gtk_menu_new();
1936 item = gtk_menu_item_new_with_label(_("More..."));
1937 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),
1940 gtk_menu_append(GTK_MENU(curmenu), item);
1941 gtk_widget_show(item);
1953 static GtkMenu *make_config_menu(GtkPspell *gtkpspell)
1955 if (!gtkpspell->popup_config_menu)
1956 gtkpspell->popup_config_menu = gtk_menu_new();
1958 debug_print("Pspell: creating/using popup_config_menu %0x\n",
1959 gtkpspell->popup_config_menu);
1960 populate_submenu(gtkpspell, gtkpspell->popup_config_menu);
1962 return GTK_MENU(gtkpspell->popup_config_menu);
1965 void gtkpspell_populate_submenu(GtkPspell *gtkpspell, GtkWidget *menuitem)
1969 menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
1971 debug_print("Pspell: using config menu %0x\n",
1972 gtkpspell->popup_config_menu);
1973 populate_submenu(gtkpspell, menu);
1975 gtkpspell->config_menu = menu;
1979 static void set_menu_pos(GtkMenu *menu, gint *x, gint *y, gpointer data)
1981 GtkPspell *gtkpspell = (GtkPspell *) data;
1982 gint xx = 0, yy = 0;
1985 GtkSText *text = GTK_STEXT(gtkpspell->gtktext);
1988 gdk_window_get_origin(GTK_WIDGET(gtkpspell->gtktext)->window, &xx, &yy);
1990 sx = gdk_screen_width();
1991 sy = gdk_screen_height();
1993 gtk_widget_get_child_requisition(GTK_WIDGET(menu), &r);
1998 *x = gtkpspell->gtktext->cursor_pos_x + xx +
1999 gdk_char_width(GTK_WIDGET(text)->style->font, ' ');
2000 *y = gtkpspell->gtktext->cursor_pos_y + yy;
2006 gdk_string_height((GTK_WIDGET(gtkpspell->gtktext))->style->font,
2007 gtkpspell->theword);
2011 /*************************************************************************/
2012 /* Menu call backs */
2014 static gboolean cancel_menu_cb(GtkMenuShell *w, gpointer data)
2016 GtkPspell *gtkpspell = (GtkPspell *) data;
2017 gtkpspell->continue_check = NULL;
2018 set_point_continue(gtkpspell);
2022 /* change_dict_cb() - Menu callback : change dict */
2023 static void change_dict_cb(GtkWidget *w, GtkPspell *gtkpspell)
2027 GtkPspeller *gtkpspeller;
2030 fullname = (gchar *) gtk_object_get_data(GTK_OBJECT(w), "dict_name");
2032 if (!strcmp2(fullname, _("None")))
2035 sug_mode = gtkpspell->default_sug_mode;
2037 dict = g_new0(Dictionary, 1);
2038 dict->fullname = g_strdup(fullname);
2039 dict->encoding = g_strdup(gtkpspell->gtkpspeller->dictionary->encoding);
2041 gtkpspeller = gtkpspeller_new(dict);
2045 message = g_strdup_printf(_("The spell checker could not change dictionary.\n%s"),
2046 gtkpspellcheckers->error_message);
2048 gtkpspell_alert_dialog(message);
2051 gtkpspeller_delete(gtkpspell->gtkpspeller);
2052 gtkpspell->gtkpspeller = gtkpspeller;
2053 gtkpspell_set_sug_mode(gtkpspell, sug_mode);
2056 dictionary_delete(dict);
2058 if (gtkpspell->config_menu)
2059 populate_submenu(gtkpspell, gtkpspell->config_menu);
2063 /******************************************************************************/
2064 /* Misc. helper functions */
2066 static void set_point_continue(GtkPspell *gtkpspell)
2070 gtktext = gtkpspell->gtktext;
2072 gtk_stext_freeze(gtktext);
2073 gtk_editable_set_position(GTK_EDITABLE(gtktext),gtkpspell->orig_pos);
2074 gtk_stext_set_point(gtktext, gtkpspell->orig_pos);
2075 gtk_stext_thaw(gtktext);
2077 if (gtkpspell->continue_check)
2078 gtkpspell->continue_check((gpointer *) gtkpspell);
2081 static void allocate_color(GtkPspell *gtkpspell, gint rgbvalue)
2084 GdkColor *color = &(gtkpspell->highlight);
2086 gc = gtk_widget_get_colormap(GTK_WIDGET(gtkpspell->gtktext));
2088 if (gtkpspell->highlight.pixel)
2089 gdk_colormap_free_colors(gc, &(gtkpspell->highlight), 1);
2091 /* Shameless copy from Sylpheed's gtkutils.c */
2093 color->red = (int) (((gdouble)((rgbvalue & 0xff0000) >> 16) / 255.0) * 65535.0);
2094 color->green = (int) (((gdouble)((rgbvalue & 0x00ff00) >> 8) / 255.0) * 65535.0);
2095 color->blue = (int) (((gdouble) (rgbvalue & 0x0000ff) / 255.0) * 65535.0);
2097 gdk_colormap_alloc_color(gc, &(gtkpspell->highlight), FALSE, TRUE);
2100 static void change_color(GtkPspell * gtkpspell,
2101 gint start, gint end,
2107 g_return_if_fail(start < end);
2109 gtktext = gtkpspell->gtktext;
2111 gtk_stext_freeze(gtktext);
2113 gtk_stext_set_point(gtktext, start);
2114 gtk_stext_forward_delete(gtktext, end - start);
2115 gtk_stext_insert(gtktext, NULL, color, NULL, newtext, end - start);
2117 gtk_stext_thaw(gtktext);
2120 /* convert_to_pspell_encoding () - converts ISO-8859-* strings to iso8859-*
2121 * as needed by pspell. Returns an allocated string.
2124 static guchar *convert_to_pspell_encoding (const guchar *encoding)
2126 guchar * pspell_encoding;
2128 if (strstr2(encoding, "ISO-8859-")) {
2129 pspell_encoding = g_strdup_printf("iso8859%s", encoding+8);
2132 if (!strcmp2(encoding, "US-ASCII"))
2133 pspell_encoding = g_strdup("iso8859-1");
2135 pspell_encoding = g_strdup(encoding);
2137 return pspell_encoding;
2140 /* compare_dict () - compare 2 dict names */
2141 static gint compare_dict(Dictionary *a, Dictionary *b)
2143 guint aparts = 0, bparts = 0;
2146 for (i=0; i < strlen(a->dictname); i++)
2147 if (a->dictname[i] == '-')
2149 for (i=0; i < strlen(b->dictname); i++)
2150 if (b->dictname[i] == '-')
2153 if (aparts != bparts)
2154 return (aparts < bparts) ? -1 : +1;
2157 compare = strcmp2(a->dictname, b->dictname);
2159 compare = strcmp2(a->fullname, b->fullname);
2165 static void dictionary_delete(Dictionary *dict)
2167 g_free(dict->fullname);
2168 g_free(dict->encoding);
2172 static Dictionary *dictionary_dup(const Dictionary *dict)
2176 dict2 = g_new(Dictionary, 1);
2178 dict2->fullname = g_strdup(dict->fullname);
2179 dict2->dictname = dict->dictname - dict->fullname + dict2->fullname;
2180 dict2->encoding = g_strdup(dict->encoding);
2185 static void free_suggestions_list(GtkPspell *gtkpspell)
2189 for (list = gtkpspell->suggestions_list; list != NULL; list = list->next)
2193 gtkpspell->max_sug = -1;
2194 gtkpspell->suggestions_list = NULL;
2198 static void reset_theword_data(GtkPspell *gtkpspell)
2200 gtkpspell->start_pos = 0;
2201 gtkpspell->end_pos = 0;
2202 gtkpspell->theword[0] = 0;
2203 gtkpspell->max_sug = -1;
2205 free_suggestions_list(gtkpspell);
2208 static void free_checkers(gpointer elt, gpointer data)
2210 GtkPspeller *gtkpspeller = elt;
2212 g_return_if_fail(gtkpspeller);
2214 gtkpspeller_real_delete(gtkpspeller);
2217 static gint find_gtkpspeller(gconstpointer aa, gconstpointer bb)
2219 Dictionary *a = ((GtkPspeller *) aa)->dictionary;
2220 Dictionary *b = ((GtkPspeller *) bb)->dictionary;
2222 if (a && b && a->fullname && b->fullname &&
2223 strcmp(a->fullname, b->fullname) == 0 &&
2224 a->encoding && b->encoding)
2225 return strcmp(a->encoding, b->encoding);
2230 static void gtkpspell_alert_dialog(gchar *message)
2235 GtkWidget *ok_button;
2237 dialog = gtk_dialog_new();
2238 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
2239 gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_MOUSE);
2240 gtk_signal_connect_object(GTK_OBJECT(dialog), "destroy",
2241 GTK_SIGNAL_FUNC(gtk_widget_destroy),
2242 GTK_OBJECT(dialog));
2244 label = gtk_label_new(message);
2245 gtk_misc_set_padding(GTK_MISC(label), 8, 8);
2247 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
2249 hbox = gtk_hbox_new(FALSE, 0);
2251 ok_button = gtk_button_new_with_label(_("OK"));
2252 GTK_WIDGET_SET_FLAGS(ok_button, GTK_CAN_DEFAULT);
2253 gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 8);
2255 gtk_signal_connect_object(GTK_OBJECT(ok_button), "clicked",
2256 GTK_SIGNAL_FUNC(gtk_widget_destroy),
2257 GTK_OBJECT(dialog));
2258 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), hbox);
2260 gtk_widget_grab_default(ok_button);
2261 gtk_widget_grab_focus(ok_button);
2262 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
2264 gtk_widget_show_all(dialog);