2005-09-19 [colin] 1.9.14cvs44
[claws.git] / src / gtk / gtkaspell.c
index 2b072d26d2e3b45c253c25ebb7b499d2bd562b64..f1c00f368f7489ec158dc4a6bcd146f6a02f2df2 100644 (file)
 
 #include <aspell.h>
 
-#include "gtk/gtktext.h"
 #include "utils.h"
 #include "codeconv.h"
-
+#include "alertpanel.h"
 #include "gtkaspell.h"
+#include "gtk/gtkutils.h"
+
 #define ASPELL_FASTMODE       1
 #define ASPELL_NORMALMODE     2
 #define ASPELL_BADSPELLERMODE 3
@@ -251,14 +252,12 @@ static void               free_checkers                   (gpointer elt,
                                                         gpointer data);
 static gint            find_gtkaspeller                (gconstpointer aa, 
                                                         gconstpointer bb);
-static void            gtkaspell_alert_dialog          (gchar *message);
 /* gtkspellconfig - only one config per session */
 GtkAspellConfig * gtkaspellconfig;
 static void destroy_menu(GtkWidget *widget, gpointer user_data);       
 
 /******************************************************************************/
 static gint get_textview_buffer_charcount(GtkTextView *view);
-static gint get_textview_buffer_position(GtkTextView *view);
 
 static gint get_textview_buffer_charcount(GtkTextView *view)
 {
@@ -326,6 +325,7 @@ void gtkaspell_checkers_quit(void)
 
                g_slist_foreach(checkers, free_checkers, NULL);
                g_slist_free(checkers);
+               gtkaspellcheckers->checkers = NULL;
        }
 
        if ((dict_list = gtkaspellcheckers->dictionary_list)) {
@@ -337,7 +337,7 @@ void gtkaspell_checkers_quit(void)
        }
 
        g_free(gtkaspellcheckers->error_message);
-
+       gtkaspellcheckers->error_message = NULL;
        return;
 }
 
@@ -437,19 +437,19 @@ GtkAspell *gtkaspell_new(const gchar *dictionary_path,
        return gtkaspell;
 }
 
-void gtkaspell_delete(GtkAspell * gtkaspell) 
+void gtkaspell_delete(GtkAspell *gtkaspell) 
 {
        GtkTextView *gtktext = gtkaspell->gtktext;
        
         g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
                                             G_CALLBACK(entry_insert_cb),
-                                     gtkaspell);
+                                            gtkaspell);
        g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
                                             G_CALLBACK(entry_delete_cb),
-                                            gtkaspell);
+                                            gtkaspell);
        g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
-                                            G_CALLBACK(button_press_intercept_cb),
-                                            gtkaspell);
+                                            G_CALLBACK(button_press_intercept_cb),
+                                            gtkaspell);
 
        gtkaspell_uncheck_all(gtkaspell);
        
@@ -471,6 +471,7 @@ void gtkaspell_delete(GtkAspell * gtkaspell)
                free_suggestions_list(gtkaspell);
 
        g_free((gchar *)gtkaspell->dictionary_path);
+       gtkaspell->dictionary_path = NULL;
 
        debug_print("Aspell: deleting gtkaspell %0x\n", (guint) gtkaspell);
 
@@ -485,7 +486,6 @@ static void entry_insert_cb(GtkTextBuffer *textbuf,
                            gint len,
                            GtkAspell *gtkaspell)
 {
-       size_t wlen;
        guint pos;
 
        g_return_if_fail(gtkaspell->gtkaspeller->checker);
@@ -810,9 +810,11 @@ static void set_sug_mode_cb(GtkMenuItem *w, GtkAspell *gtkaspell)
 {
        char *themode;
        
-       gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), (gchar **) &themode);
+       themode = (char *) gtk_label_get_text(GTK_LABEL(GTK_BIN(w)->child));
+       themode = g_strdup(themode);
        
        set_real_sug_mode(gtkaspell, themode);
+       g_free(themode);
 
        if (gtkaspell->config_menu)
                populate_submenu(gtkaspell, gtkaspell->config_menu);
@@ -896,7 +898,7 @@ static GList *misspelled_suggest(GtkAspell *gtkaspell, guchar *word)
                elements    = aspell_word_list_elements(suggestions);
                list        = g_list_append(list, g_strdup(word)); 
                
-               while (newword = aspell_string_enumeration_next(elements))
+               while ((newword = aspell_string_enumeration_next(elements)) != NULL)
                        list = g_list_append(list, g_strdup(newword));
 
                gtkaspell->max_sug          = g_list_length(list) - 1;
@@ -920,7 +922,7 @@ static int misspelled_test(GtkAspell *gtkaspell, unsigned char *word)
 
 static gboolean iswordsep(unsigned char c) 
 {
-       return !isalpha(c) && c != '\'';
+       return (isspace(c) || ispunct(c)) && c != '\'';
 }
 
 static guchar get_text_index_whar(GtkAspell *gtkaspell, int pos) 
@@ -980,7 +982,11 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
                c = get_text_index_whar(gtkaspell, start);
                if (c == '\'') {
                        if (start > 0) {
-                               if (!isalpha(get_text_index_whar(gtkaspell,
+                               if (isspace(get_text_index_whar(gtkaspell,
+                                                                start - 1))
+                               ||  ispunct(get_text_index_whar(gtkaspell,
+                                                                start - 1))
+                               ||  isdigit(get_text_index_whar(gtkaspell,
                                                                 start - 1))) {
                                        /* start_quote = TRUE; */
                                        break;
@@ -991,7 +997,7 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
                                break;
                        }
                }
-               else if (!isalpha(c))
+               else if (isspace(c) || ispunct(c) || isdigit(c))
                                break;
        }
 
@@ -1001,7 +1007,11 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
                c = get_text_index_whar(gtkaspell, end); 
                if (c == '\'') {
                        if (end < get_textview_buffer_charcount(gtktext)) {
-                               if (!isalpha(get_text_index_whar(gtkaspell,
+                               if (isspace(get_text_index_whar(gtkaspell,
+                                                                end + 1))
+                               ||  ispunct(get_text_index_whar(gtkaspell,
+                                                                end + 1))
+                               ||  isdigit(get_text_index_whar(gtkaspell,
                                                                 end + 1))) {
                                        /* end_quote = TRUE; */
                                        break;
@@ -1012,7 +1022,7 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
                                break;
                        }
                }
-               else if(!isalpha(c))
+               else if (isspace(c) || ispunct(c) || isdigit(c))
                                break;
        }
                                                
@@ -1023,11 +1033,18 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
 
        if (buf) {
                if (end - start < buflen) {
-                       for (pos = start; pos < end; pos++) {
-                               buf[pos - start] =
-                                       get_text_index_whar(gtkaspell, pos);
-                       }
-                       buf[pos - start] = 0;
+                       GtkTextIter iterstart, iterend;
+                       gchar *tmp, *conv;
+                       GtkTextBuffer *buffer = gtk_text_view_get_buffer(gtktext);
+                       gtk_text_buffer_get_iter_at_offset(buffer, &iterstart, start);
+                       gtk_text_buffer_get_iter_at_offset(buffer, &iterend, end);
+                       tmp = gtk_text_buffer_get_text(buffer, &iterstart, &iterend, FALSE);
+                       conv = conv_iconv_strdup(tmp, CS_UTF_8, 
+                               gtkaspell->gtkaspeller->dictionary->encoding);
+                       g_free(tmp);
+                       strncpy(buf, conv, buflen-1);
+                       buf[buflen]='\0';
+                       g_free(conv);
                } else
                        return FALSE;
        }
@@ -1048,7 +1065,6 @@ static gboolean check_at(GtkAspell *gtkaspell, gint from_pos)
        if (!get_word_from_pos(gtkaspell, from_pos, buf, sizeof(buf), 
                               &start, &end))
                return FALSE;
-
        if (misspelled_test(gtkaspell, buf)) {
                strncpy(gtkaspell->theword, buf, GTKASPELLWORDSIZE - 1);
                gtkaspell->theword[GTKASPELLWORDSIZE - 1] = 0;
@@ -1125,7 +1141,7 @@ static gboolean check_next_prev(GtkAspell *gtkaspell, gboolean forward)
        } else {
                reset_theword_data(gtkaspell);
 
-               gtkaspell_alert_dialog(_("No misspelled word found."));
+               alertpanel_notice(_("No misspelled word found."));
                set_textview_buffer_offset(gtkaspell->gtktext,
                                          gtkaspell->orig_pos);
        }
@@ -1227,7 +1243,7 @@ static void replace_with_supplied_word_cb(GtkWidget *w, GtkAspell *gtkaspell)
 {
        unsigned char *newword;
        GdkEvent *e= (GdkEvent *) gtk_get_current_event();
-       
+
        newword = gtk_editable_get_chars(GTK_EDITABLE(gtkaspell->replace_entry),
                                         0, -1);
 
@@ -1246,6 +1262,10 @@ static void replace_with_supplied_word_cb(GtkWidget *w, GtkAspell *gtkaspell)
 
        g_free(newword);
 
+       if (w && GTK_IS_DIALOG(w)) {
+               gtk_widget_destroy(w);
+       }
+
        set_point_continue(gtkaspell);
 }
 
@@ -1256,7 +1276,8 @@ static void replace_word_cb(GtkWidget *w, gpointer data)
        GtkAspell *gtkaspell = (GtkAspell *) data;
        GdkEvent *e= (GdkEvent *) gtk_get_current_event();
 
-       gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), (gchar**) &newword);
+       newword = (unsigned char *) gtk_label_get_text(GTK_LABEL(GTK_BIN(w)->child));
+       newword = g_strdup(newword);
 
        replace_real_word(gtkaspell, newword);
 
@@ -1273,6 +1294,7 @@ static void replace_word_cb(GtkWidget *w, gpointer data)
        gtk_menu_shell_deactivate(GTK_MENU_SHELL(w->parent));
 
        set_point_continue(gtkaspell);
+       g_free(newword);
 }
 
 static void replace_real_word(GtkAspell *gtkaspell, gchar *newword)
@@ -1280,7 +1302,6 @@ static void replace_real_word(GtkAspell *gtkaspell, gchar *newword)
        int             oldlen, newlen, wordlen;
        gint            origpos;
        gint            pos;
-       gint            start = gtkaspell->start_pos;
        GtkTextView     *gtktext;
        GtkTextBuffer   *textbuf;
        GtkTextIter     startiter, enditer;
@@ -1375,7 +1396,6 @@ static void add_word_to_session_cb(GtkWidget *w, gpointer data)
 static void add_word_to_personal_cb(GtkWidget *w, gpointer data)
 {
        GtkAspell *gtkaspell = (GtkAspell *) data; 
-       GtkTextView *gtktext    = gtkaspell->gtktext;
 
        aspell_speller_add_to_personal(gtkaspell->gtkaspeller->checker,
                                       gtkaspell->theword,
@@ -1423,14 +1443,33 @@ static void check_with_alternate_cb(GtkWidget *w, gpointer data)
        set_point_continue(gtkaspell);
 }
        
+static gboolean replace_key_pressed(GtkWidget *widget,
+                                  GdkEventKey *event,
+                                  GtkAspell *gtkaspell)
+{
+       if (event && event->keyval == GDK_Escape) {
+               gtk_widget_destroy(widget);
+               return TRUE;
+       } else if (event && event->keyval == GDK_Return) {
+               replace_with_supplied_word_cb(widget, gtkaspell);
+               return TRUE;
+       }
+       return FALSE;
+}
+       
 static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
 {
+       static PangoFontDescription *font_desc;
        GtkWidget *dialog;
        GtkWidget *label;
+       GtkWidget *w_hbox;
        GtkWidget *hbox;
+       GtkWidget *vbox;
        GtkWidget *entry;
        GtkWidget *ok_button;
        GtkWidget *cancel_button;
+       GtkWidget *confirm_area;
+       GtkWidget *icon;
        gchar *thelabel;
        gint xx, yy;
        GtkAspell *gtkaspell = (GtkAspell *) data;
@@ -1443,47 +1482,83 @@ static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
 
        gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
        gtk_window_set_title(GTK_WINDOW(dialog),_("Replace unknown word"));
+       gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
        gtk_widget_set_uposition(dialog, xx, yy);
 
        g_signal_connect_swapped(G_OBJECT(dialog), "destroy",
                                 G_CALLBACK(gtk_widget_destroy), 
                                 G_OBJECT(dialog));
 
-       hbox = gtk_hbox_new(FALSE, 0);
-       gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
+       gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
+       hbox = gtk_hbox_new (FALSE, 12);
+       gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
+       gtk_widget_show (hbox);
+       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
+                           FALSE, FALSE, 0);
 
-       thelabel = g_strdup_printf(_("Replace \"%s\" with: "), 
+       thelabel = g_strdup_printf(_("<span weight=\"bold\" "
+                                       "size=\"larger\">Replace \"%s\" with: </span>"), 
                                   gtkaspell->theword);
+       /* for title label */
+       w_hbox = gtk_hbox_new(FALSE, 0);
+       
+       icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
+                                       GTK_ICON_SIZE_DIALOG); 
+       gtk_misc_set_alignment (GTK_MISC (icon), 0.5, 0.0);
+       gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
+       
+       vbox = gtk_vbox_new (FALSE, 12);
+       gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+       gtk_widget_show (vbox);
+       
        label = gtk_label_new(thelabel);
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+       gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
+       gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+       gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+       gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+       if (!font_desc) {
+               gint size;
+
+               size = pango_font_description_get_size
+                       (label->style->font_desc);
+               font_desc = pango_font_description_new();
+               pango_font_description_set_weight
+                       (font_desc, PANGO_WEIGHT_BOLD);
+               pango_font_description_set_size
+                       (font_desc, size * PANGO_SCALE_LARGE);
+       }
+       if (font_desc)
+               gtk_widget_modify_font(label, font_desc);
        g_free(thelabel);
-       gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
-
+       
        entry = gtk_entry_new();
        gtkaspell->replace_entry = entry;
        gtk_entry_set_text(GTK_ENTRY(entry), gtkaspell->theword);
        gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
-       g_signal_connect(G_OBJECT(entry), "activate",
-                        G_CALLBACK(replace_with_supplied_word_cb), 
-                        gtkaspell);
-       g_signal_connect_swapped(G_OBJECT(entry), "activate",
-                                G_CALLBACK(gtk_widget_destroy), 
-                                G_OBJECT(dialog));
-       gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
+       g_signal_connect(G_OBJECT(dialog),
+                       "key_press_event",
+                       G_CALLBACK(replace_key_pressed), gtkaspell);
+       gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
 
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, 
-                          TRUE, 0);
        label = gtk_label_new(_("Holding down Control key while pressing "
                                "Enter\nwill learn from mistake.\n"));
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
-       gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
-       gtk_misc_set_padding(GTK_MISC(label), 8, 0);
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, 
-                       TRUE, TRUE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+       gtk_widget_show(label);
 
        hbox = gtk_hbox_new(TRUE, 0);
 
-       ok_button = gtk_button_new_with_label(_("OK"));
-       gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 8);
+       gtkut_stock_button_set_create(&confirm_area,
+                                     &ok_button, GTK_STOCK_OK,
+                                     &cancel_button, GTK_STOCK_CANCEL,
+                                     NULL, NULL);
+
+       gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area),
+                        confirm_area, FALSE, FALSE, 0);
+       gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
+
        g_signal_connect(G_OBJECT(ok_button), "clicked",
                         G_CALLBACK(replace_with_supplied_word_cb), 
                         gtkaspell);
@@ -1491,14 +1566,10 @@ static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
                                   G_CALLBACK(gtk_widget_destroy), 
                                   G_OBJECT(dialog));
 
-       cancel_button = gtk_button_new_with_label(_("Cancel"));
-       gtk_box_pack_start(GTK_BOX(hbox), cancel_button, TRUE, TRUE, 8);
        g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked",
                                 G_CALLBACK(gtk_widget_destroy), 
                                 G_OBJECT(dialog));
 
-       gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), hbox);
-
        gtk_widget_grab_focus(entry);
 
        gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
@@ -1508,9 +1579,6 @@ static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
 
 void gtkaspell_uncheck_all(GtkAspell * gtkaspell) 
 {
-       gint      origpos;
-       gchar    *text;
-       gfloat    adj_value;
        GtkTextView *gtktext;
        GtkTextBuffer *buffer;
        GtkTextIter startiter, enditer;
@@ -1572,17 +1640,7 @@ GSList *gtkaspell_get_dictionary_list(const gchar *aspell_path, gint refresh)
        list = NULL;
 
        config = new_aspell_config();
-#if 0 
-       aspell_config_replace(config, "rem-all-word-list-path", "");
-       if (aspell_config_error_number(config) != 0) {
-               gtkaspellcheckers->error_message = g_strdup(
-                               aspell_config_error_message(config));
-               gtkaspellcheckers->dictionary_list =
-                       create_empty_dictionary_list();
 
-               return gtkaspellcheckers->dictionary_list; 
-       }
-#endif
        aspell_config_replace(config, "dict-dir", aspell_path);
        if (aspell_config_error_number(config) != 0) {
                gtkaspellcheckers->error_message = g_strdup(
@@ -1605,8 +1663,15 @@ GSList *gtkaspell_get_dictionary_list(const gchar *aspell_path, gint refresh)
                                entry->name);
                dict->dictname = dict->fullname + strlen(aspell_path);
                dict->encoding = g_strdup(entry->code);
-               debug_print("Aspell: found dictionary %s %s\n", dict->fullname,
-                               dict->dictname);
+               
+               if (g_slist_find_custom(list, dict, 
+                               (GCompareFunc) compare_dict) != NULL) {
+                       dictionary_delete(dict);
+                       continue;       
+               }
+               
+               debug_print("Aspell: found dictionary %s %s %s\n", dict->fullname,
+                               dict->dictname, dict->encoding);
                list = g_slist_insert_sorted(list, dict,
                                (GCompareFunc) compare_dict);
        }
@@ -1834,7 +1899,7 @@ static gboolean aspell_key_pressed(GtkWidget *widget,
                                   GdkEventKey *event,
                                   GtkAspell *gtkaspell)
 {
-       if (event && isascii(event->keyval)) {
+       if (event && (isascii(event->keyval) || event->keyval == GDK_Return)) {
                gtk_accel_groups_activate(
                                G_OBJECT(gtkaspell->parent_window),
                                event->keyval, event->state);
@@ -1875,10 +1940,14 @@ static GtkMenu *make_sug_menu(GtkAspell *gtkaspell)
        g_signal_connect(G_OBJECT(menu), "cancel",
                         G_CALLBACK(cancel_menu_cb), gtkaspell);
 
+       utf8buf  = conv_codeset_strdup((unsigned char*)l->data,
+                               conv_get_locale_charset_str(),
+                               CS_UTF_8);
        caption = g_strdup_printf(_("\"%s\" unknown in %s"), 
-                                 (unsigned char*) l->data
+                                 utf8buf
                                  gtkaspell->gtkaspeller->dictionary->dictname);
        item = gtk_menu_item_new_with_label(caption);
+       g_free(utf8buf);
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu), item);
        gtk_misc_set_alignment(GTK_MISC(GTK_BIN(item)->child), 0.5, 0.5);
@@ -1916,6 +1985,9 @@ static GtkMenu *make_sug_menu(GtkAspell *gtkaspell)
                         gtkaspell);
        gtk_widget_add_accelerator(item, "activate", accel, GDK_R, 0,
                                   GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
+       gtk_widget_add_accelerator(item, "activate", accel, GDK_R, 
+                                  GDK_CONTROL_MASK,
+                                  GTK_ACCEL_LOCKED);
 
        if (gtkaspell->use_alternate && gtkaspell->alternate_speller) {
                caption = g_strdup_printf(_("Check with %s"), 
@@ -1929,6 +2001,9 @@ static GtkMenu *make_sug_menu(GtkAspell *gtkaspell)
                                 gtkaspell);
                gtk_widget_add_accelerator(item, "activate", accel, GDK_X, 0,
                                           GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
+               gtk_widget_add_accelerator(item, "activate", accel, GDK_X, 
+                                          GDK_CONTROL_MASK,
+                                          GTK_ACCEL_LOCKED);
        }
 
        item = gtk_menu_item_new();
@@ -1961,6 +2036,7 @@ static GtkMenu *make_sug_menu(GtkAspell *gtkaspell)
                                                        conv_get_locale_charset_str(),
                                                        CS_UTF_8);
                        item = gtk_menu_item_new_with_label(utf8buf);
+                       g_free(utf8buf);
                        gtk_widget_show(item);
                        gtk_menu_append(GTK_MENU(curmenu), item);
                        g_signal_connect(G_OBJECT(item), "activate",
@@ -2244,6 +2320,7 @@ gboolean gtkaspell_change_dict(GtkAspell *gtkaspell, const gchar *dictionary)
            dict == gtkaspell->alternate_speller->dictionary) {
                use_alternate_dict(gtkaspell);
                dictionary_delete(dict);
+               gtkaspell->alternate_speller->dictionary = NULL;
                return TRUE;
        }
        
@@ -2254,7 +2331,7 @@ gboolean gtkaspell_change_dict(GtkAspell *gtkaspell, const gchar *dictionary)
                message = g_strdup_printf(_("The spell checker could not change dictionary.\n%s"), 
                                          gtkaspellcheckers->error_message);
 
-               gtkaspell_alert_dialog(message); 
+               alertpanel_warning(message); 
                g_free(message);
        } else {
                if (gtkaspell->use_alternate) {
@@ -2337,7 +2414,8 @@ static void change_color(GtkAspell * gtkaspell,
        GtkTextBuffer *buffer;
        GtkTextIter startiter, enditer;
 
-       g_return_if_fail(start < end);
+       if (start > end)
+               return;
     
        gtktext = gtkaspell->gtktext;
     
@@ -2425,7 +2503,7 @@ static void free_suggestions_list(GtkAspell *gtkaspell)
             list = list->next)
                g_free(list->data);
 
-       g_list_free(list);
+       g_list_free(gtkaspell->suggestions_list);
        
        gtkaspell->max_sug          = -1;
        gtkaspell->suggestions_list = NULL;
@@ -2462,41 +2540,4 @@ static gint find_gtkaspeller(gconstpointer aa, gconstpointer bb)
 
        return 1;
 }
-
-static void gtkaspell_alert_dialog(gchar *message)
-{
-       GtkWidget *dialog;
-       GtkWidget *hbox;
-       GtkWidget *label;
-       GtkWidget *ok_button;
-
-       dialog = gtk_dialog_new();
-       gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
-       gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
-       g_signal_connect_swapped(G_OBJECT(dialog), "destroy",
-                                G_CALLBACK(gtk_widget_destroy), 
-                                G_OBJECT(dialog));
-
-       label  = gtk_label_new(message);
-       gtk_misc_set_padding(GTK_MISC(label), 8, 8);
-
-       gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
-       
-       hbox = gtk_hbox_new(FALSE, 0);
-
-       ok_button = gtk_button_new_with_label(_("OK"));
-       GTK_WIDGET_SET_FLAGS(ok_button, GTK_CAN_DEFAULT);
-       gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 8);    
-
-       g_signal_connect_swapped(G_OBJECT(ok_button), "clicked",
-                                G_CALLBACK(gtk_widget_destroy), 
-                                G_OBJECT(dialog));
-       gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), hbox);
-                       
-       gtk_widget_grab_default(ok_button);
-       gtk_widget_grab_focus(ok_button);
-       gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
-
-       gtk_widget_show_all(dialog);
-}
 #endif