Various bug fixes and enhancements, see ChangeLog.claws 2002-02-03
authorMelvin Hadasht <melvin.hadasht@free.fr>
Sun, 3 Feb 2002 15:10:17 +0000 (15:10 +0000)
committerMelvin Hadasht <melvin.hadasht@free.fr>
Sun, 3 Feb 2002 15:10:17 +0000 (15:10 +0000)
ChangeLog.claws
configure.in
src/compose.c
src/gtkspell.c
src/gtkspell.h

index ec48820ee1d146fb355f5e28e9fd15bd92d93ee4..a20d6606883299e7493af68c9dbcfd982f6fb9e3 100644 (file)
@@ -1,3 +1,22 @@
+2002-02-03 [melvin]    0.7.0claws45
+
+       * src/gtkspell.[ch]
+               Readded function to highlight all misspelled words.
+               Fixed bug where user-provided-words did not replace
+                       correctly the misspelled word when using the mouse.
+               Fixed bug where checking a region selected from right to left did
+                       not check the region at all.
+               Fixed bug where 'Check backwards' may not check at all. 
+               Fixed memory leaks where popup menus and accel_groups were not destroyed.
+               Fixed possible buffer overflow when checking for long strings (>1k).
+               Made cursor and scrollbar positions non changing after uncheck_all/check_all.
+               Accelerators code uses now gtk_widget_add_accel.
+               Removed and disabled obsolete and unfinished code.
+               Cleaning up.
+
+       * src/compose.c
+               Added menu item to Highlight all misspelled words.
+
 2002-02-01 [paul]      0.7.0claws44
 
        * src/mainwindow.c
index 00a63972ac6d8cc476354f6d6edbf6e71c1c9e6b..47eca440bcc69a85bd68f00319877f0b4e72ee4e 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws44
+EXTRA_VERSION=claws45
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 2bf2660c59dd04b27a7dcc1e9f2ecc48b4d0742f..10b1b1391a8c3fae5c6dc1dba8bb15ba18b4a0b4 100644 (file)
@@ -450,11 +450,10 @@ void compose_headerentry_key_press_event_cb(GtkWidget            *entry,
 
 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
 
-
 #if USE_PSPELL
 static void compose_check_all             (Compose *compose);
+static void compose_highlight_all         (Compose *compose);
 static void compose_check_backwards       (Compose *compose);
-
 static void compose_check_forwards_go     (Compose *compose);
 #endif
 
@@ -462,7 +461,6 @@ static gboolean compose_send_control_enter (Compose *compose);
 static void text_activated                (GtkWidget   *widget,
                                            Compose     *compose);
 
-
 static GtkItemFactoryEntry compose_popup_entries[] =
 {
        {N_("/_Add..."),        NULL, compose_attach_cb, 0, NULL},
@@ -568,11 +566,17 @@ static GtkItemFactoryEntry compose_entries[] =
                                        "<control>X", compose_ext_editor_cb, 0, NULL},
 #if USE_PSPELL
        {N_("/_Spelling"),              NULL, NULL, 0, "<Branch>"},
-       {N_("/_Spelling/Check all or selection"),NULL, compose_check_all, 0, NULL},
-       {N_("/_Spelling/Check backwards misspelled word"),      NULL, compose_check_backwards , 0, NULL},
-       {N_("/_Spelling/Forward to next misspelled word"),      NULL, compose_check_forwards_go, 0, NULL},
+       {N_("/_Spelling/_Check all or check selection"),
+                                       NULL, compose_check_all, 0, NULL},
+       {N_("/_Spelling/_Highlight all misspelled words"),
+                                       NULL, compose_highlight_all, 0, NULL},
+       {N_("/_Spelling/Check _backwards misspelled word"),
+                                       NULL, compose_check_backwards , 0, NULL},
+       {N_("/_Spelling/_Forward to next misspelled word"),
+                                       NULL, compose_check_forwards_go, 0, NULL},
        {N_("/_Spelling/---"),          NULL, NULL, 0, "<Separator>"},
-       {N_("/_Spelling/Spelling Configuration"),NULL, NULL, 0, "<Branch>"},
+       {N_("/_Spelling/_Spelling Configuration"),
+                                       NULL, NULL, 0, "<Branch>"},
 #endif
 #if 0 /* NEW COMPOSE GUI */
        {N_("/_View"),                  NULL, NULL, 0, "<Branch>"},
@@ -4655,16 +4659,22 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
         if (prefs_common.enable_pspell) {
                gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
                                          conv_get_current_charset_str(),
+                                         prefs_common.misspelled_col,
                                          prefs_common.check_while_typing,
                                          GTK_STEXT(text));
                if (!gtkpspell) {
                        alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
-                       gtkpspell_checkers_reset();
+                       gtkpspell_checkers_reset_error();
                } else {
 
                        GtkWidget *menuitem;
 
-                       gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode);
+                       if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
+                               debug_print(_("Pspell: could not set suggestion mode %s"),
+                                   gtkpspellcheckers->error_message);
+                               gtkpspell_checkers_reset_error();
+                       }
+
                        menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
                        gtkpspell_populate_submenu(gtkpspell, menuitem);
                        menu_set_sensitive(ifactory, "/Spelling", TRUE);
@@ -6647,6 +6657,12 @@ static void compose_check_all(Compose *compose)
                gtkpspell_check_all(compose->gtkpspell);
 }
 
+static void compose_highlight_all(Compose *compose)
+{
+       if (compose->gtkpspell)
+               gtkpspell_highlight_all(compose->gtkpspell);
+}
+
 static void compose_check_backwards(Compose *compose)
 {
        if (compose->gtkpspell) 
index 5884c9445807a8c32425b4b339b65c7a873dee9a..09e3bff83b0534c81e53769746b8e34c91dd39a7 100644 (file)
@@ -108,7 +108,7 @@ static GtkPspeller *        gtkpspeller_real_delete         (GtkPspeller *gtkpspeller);
 /* Checker configuration */
 static gint            set_dictionary                  (PspellConfig *config, 
                                                         Dictionary *dict);
-static void            set_sug_mode_cb                 (GtkWidget *w, 
+static void            set_sug_mode_cb                 (GtkMenuItem *w, 
                                                         GtkPspell *gtkpspell);
 static void            set_real_sug_mode               (GtkPspell *gtkpspell, 
                                                         const char *themode);
@@ -120,17 +120,19 @@ static gboolean           check_next_prev                 (GtkPspell *gtkpspell,
                                                         gboolean forward);
 static GList*          misspelled_suggest              (GtkPspell *gtkpspell, 
                                                         guchar *word);
-static void            add_word_to_session             (GtkWidget *w, 
-                                                        GtkPspell *d);
-static void            add_word_to_personal            (GtkWidget *w, 
-                                                        GtkPspell *d);
-static void            replace_word                    (GtkWidget *w, 
-                                                        GtkPspell *gtkpspell); 
+static void            add_word_to_session_cb          (GtkWidget *w, 
+                                                        gpointer data);
+static void            add_word_to_personal_cb         (GtkWidget *w, 
+                                                        gpointer data);
+static void            replace_with_create_dialog_cb   (GtkWidget *w,
+                                                        gpointer data);
+static void            replace_with_supplied_word_cb   (GtkWidget *w, 
+                                                        GtkPspell *gtkpspell);
+static void            replace_word_cb                 (GtkWidget *w, 
+                                                        gpointer data); 
 static void            replace_real_word               (GtkPspell *gtkpspell, 
                                                         gchar *newword);
-static void            check_all_cb                    (GtkWidget *w, 
-                                                        GtkPspell *gtkpspell);
-static void            toggle_check_while_typing       (GtkWidget *w, 
+static void            toggle_check_while_typing_cb    (GtkWidget *w, 
                                                         gpointer data);
 
 /* Menu creation */
@@ -145,26 +147,29 @@ static void               set_menu_pos                    (GtkMenu *menu,
                                                         gint *y, 
                                                         gpointer data);
 /* Other menu callbacks */
-static gboolean        deactivate_menu_cb              (GtkWidget *w, 
-                                                        gpointer *data);
 static gboolean        cancel_menu_cb                  (GtkMenuShell *w,
                                                         gpointer data);
 static void            change_dict_cb                  (GtkWidget *w, 
                                                         GtkPspell *gtkpspell);
 
 /* Misc. helper functions */
-static void continue_check(gpointer *gtkpspell);
+static void            set_point_continue              (GtkPspell *gtkpspell);
+static void            continue_check                  (gpointer *gtkpspell);
 static gboolean        iswordsep                       (unsigned char c);
 static guchar          get_text_index_whar             (GtkPspell *gtkpspell, 
                                                         int pos);
 static gboolean        get_word_from_pos               (GtkPspell *gtkpspell, 
-                                                        int pos, 
+                                                        gint pos, 
                                                         unsigned char* buf,
-                                                        int *pstart, int *pend);
-static void            allocate_color                  (GtkPspell *gtkpspell);
+                                                        gint buflen,
+                                                        gint *pstart, 
+                                                        gint *pend);
+static void            allocate_color                  (GtkPspell *gtkpspell,
+                                                        gint rgbvalue);
 static void            change_color                    (GtkPspell *gtkpspell, 
-                                                        int start, 
-                                                        int end, 
+                                                        gint start, 
+                                                        gint end, 
+                                                        gchar *newtext,
                                                         GdkColor *color);
 static guchar*         convert_to_pspell_encoding      (const guchar *encoding);
 static gint            compare_dict                    (Dictionary *a, 
@@ -238,7 +243,7 @@ static void gtkpspell_checkers_error_message (gchar *message)
        } else gtkpspellcheckers->error_message = message;
 }
 
-void gtkpspell_checkers_reset()
+void gtkpspell_checkers_reset_error()
 {
        g_return_if_fail(gtkpspellcheckers);
        
@@ -248,7 +253,8 @@ void gtkpspell_checkers_reset()
 }
 
 GtkPspell *gtkpspell_new(const gchar *dictionary, 
-                        const gchar *encoding, 
+                        const gchar *encoding,
+                        gint  misspelled_color,
                         gboolean check_while_typing,
                         GtkSText *gtktext)
 {
@@ -260,7 +266,7 @@ GtkPspell *gtkpspell_new(const gchar *dictionary,
        
        dict->fullname = g_strdup(dictionary);
        dict->encoding = g_strdup(encoding);
-       gtkpspeller = gtkpspeller_new(dict); 
+       gtkpspeller    = gtkpspeller_new(dict); 
        dictionary_delete(dict);
 
        if (!gtkpspeller)
@@ -268,31 +274,35 @@ GtkPspell *gtkpspell_new(const gchar *dictionary,
        
        gtkpspell = g_new(GtkPspell, 1);
 
-       gtkpspell->gtkpspeller = gtkpspeller;
-       gtkpspell->theword[0]  = 0x00;
-       gtkpspell->start_pos   = 0;
-       gtkpspell->end_pos     = 0;
-       gtkpspell->orig_pos    = -1;
-       
+       gtkpspell->gtkpspeller        = gtkpspeller;
+       gtkpspell->theword[0]         = 0x00;
+       gtkpspell->start_pos          = 0;
+       gtkpspell->end_pos            = 0;
+       gtkpspell->orig_pos           = -1;
+       gtkpspell->end_check_pos      = -1;
+       gtkpspell->misspelled         = -1;
        gtkpspell->check_while_typing = check_while_typing;
-
-       gtkpspell->gtktext     = gtktext;
-
+       gtkpspell->continue_check     = NULL;
+       gtkpspell->config_menu        = NULL;
+       gtkpspell->popup_config_menu  = NULL;
+       gtkpspell->sug_menu           = NULL;
+       gtkpspell->replace_entry      = NULL;
+       gtkpspell->gtktext            = gtktext;
        gtkpspell->default_sug_mode   = PSPELL_FASTMODE;
-       gtkpspell->max_sug            = -1;
+       gtkpspell->max_sug            = -1;
        gtkpspell->suggestions_list   = NULL;
 
+       allocate_color(gtkpspell, misspelled_color);
+
        gtk_signal_connect_after(GTK_OBJECT(gtktext), "insert-text",
                                 GTK_SIGNAL_FUNC(entry_insert_cb), gtkpspell);
-
        gtk_signal_connect_after(GTK_OBJECT(gtktext), "delete-text",
                                 GTK_SIGNAL_FUNC(entry_delete_cb), gtkpspell);
-       
        gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event",
                           GTK_SIGNAL_FUNC(button_press_intercept_cb), gtkpspell);
        
-       allocate_color(gtkpspell);
-       
+       debug_print("Pspell: created gtkpspell %0x\n", gtkpspell);
+
        return gtkpspell;
 }
 
@@ -314,7 +324,19 @@ void gtkpspell_delete(GtkPspell * gtkpspell)
        
        gtkpspeller_delete(gtkpspell->gtkpspeller);
 
+       if (gtkpspell->sug_menu)
+               gtk_widget_destroy(gtkpspell->sug_menu);
+       if (gtkpspell->popup_config_menu)
+               gtk_widget_destroy(gtkpspell->popup_config_menu);
+       if (gtkpspell->config_menu)
+               gtk_widget_destroy(gtkpspell->config_menu);
+       if (gtkpspell->suggestions_list)
+               free_suggestions_list(gtkpspell);
+       
+       debug_print("Pspell: deleting gtkpspell %0x\n", gtkpspell);
+
        g_free(gtkpspell);
+
        gtkpspell = NULL;
 }
 
@@ -423,12 +445,11 @@ static gint button_press_intercept_cb(GtkSText *gtktext, GdkEvent *e, GtkPspell
 /* Checker creation */
 static GtkPspeller *gtkpspeller_new(Dictionary *dictionary)
 {
-       GSList          *checkers, *exist;
+       GSList          *exist;
        GtkPspeller     *gtkpspeller = NULL;
-       GtkPspeller     *g           = g_new(GtkPspeller, 1);
+       GtkPspeller     *g           = g_new0(GtkPspeller, 1);
        Dictionary      *dict;
        gint            ispell;
-       gboolean        free_dict = TRUE;
                
        g_return_val_if_fail(gtkpspellcheckers, NULL);
 
@@ -456,37 +477,34 @@ static GtkPspeller *gtkpspeller_new(Dictionary *dictionary)
 
        g->dictionary = dict;
 
-       checkers = gtkpspellcheckers->checkers;
-
-       exist = g_slist_find_custom(checkers, g, find_gtkpspeller);
+       exist = g_slist_find_custom(gtkpspellcheckers->checkers, g, 
+                                   find_gtkpspeller);
        
        g_free(g);
 
-       if (exist)
+       if (exist && ispell) {
                gtkpspeller = (GtkPspeller *) exist->data;
+               dictionary_delete(dict);
 
-       if (exist && ispell)
                debug_print(_("Pspell: Using existing ispell checker %0x\n"),
                            (gint) gtkpspeller);
-       else {
+       else {
                if ((gtkpspeller = gtkpspeller_real_new(dict)) != NULL) {
-                       checkers = g_slist_append(checkers, gtkpspeller);
-                       
+                       gtkpspellcheckers->checkers = g_slist_append(
+                                               gtkpspellcheckers->checkers,
+                                               gtkpspeller);
+
                        debug_print(_("Pspell: Created a new gtkpspeller %0x\n"),
                                    (gint) gtkpspeller);
-                       
-                       free_dict = FALSE;
-               } else 
+               } else {
+                       dictionary_delete(dict);
+
                        debug_print(_("Pspell: Could not create spell checker.\n"));
+               }
        }
 
        debug_print(_("Pspell: number of existing checkers %d\n"), 
-                   g_slist_length(checkers));
-
-       if (free_dict)
-               dictionary_delete(dict);
-
-       gtkpspellcheckers->checkers = checkers;
+                   g_slist_length(gtkpspellcheckers->checkers));
 
        return gtkpspeller;
 }
@@ -530,20 +548,15 @@ static GtkPspeller *gtkpspeller_real_new(Dictionary *dict)
 
 static GtkPspeller *gtkpspeller_delete(GtkPspeller *gtkpspeller)
 {
-       GSList *checkers;
-
        g_return_val_if_fail(gtkpspellcheckers, NULL);
        
-       checkers = gtkpspellcheckers->checkers;
-       
        if (gtkpspeller->ispell) 
                debug_print(_("Pspell: Won't remove existing ispell checker %0x.\n"), 
                            (gint) gtkpspeller);
        else {
-               checkers = g_slist_remove(checkers, gtkpspeller);
+               gtkpspellcheckers->checkers = g_slist_remove(gtkpspellcheckers->checkers, 
+                                               gtkpspeller);
 
-               gtkpspellcheckers->checkers = checkers;
-               
                debug_print(_("Pspell: Deleting gtkpspeller %0x.\n"), 
                            (gint) gtkpspeller);
                
@@ -551,7 +564,7 @@ static GtkPspeller *gtkpspeller_delete(GtkPspeller *gtkpspeller)
        }
 
        debug_print(_("Pspell: number of existing checkers %d\n"), 
-                   g_slist_length(checkers));
+                   g_slist_length(gtkpspellcheckers->checkers));
 
        return gtkpspeller;
 }
@@ -593,10 +606,10 @@ static gboolean set_dictionary(PspellConfig *config, Dictionary *dict)
        buf[dict->dictname - dict->fullname] = 0x00;
 
        CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("rem-all-word-list-path", "");
-       debug_print(_("Pspell: removing all paths.\n"));
+       debug_print(_("Pspell: removed all paths.\n"));
 
        CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("add-word-list-path", buf);
-       debug_print(_("Pspell: adding path (%s).\n"), buf);
+       debug_print(_("Pspell: added path %s.\n"), buf);
 
        strncpy(buf, dict->dictname, BUFSIZE-1);
        language = buf;
@@ -678,9 +691,9 @@ guchar *gtkpspell_get_path(GtkPspell *gtkpspell)
 }
 
 /* set_sug_mode_cb() - Menu callback : Set the suggestion mode */
-static void set_sug_mode_cb(GtkWidget *w, GtkPspell *gtkpspell)
+static void set_sug_mode_cb(GtkMenuItem *w, GtkPspell *gtkpspell)
 {
-       unsigned char *themode;
+       char *themode;
        
        if (gtkpspell->gtkpspeller->ispell) return;
 
@@ -694,22 +707,22 @@ static void set_sug_mode_cb(GtkWidget *w, GtkPspell *gtkpspell)
 static void set_real_sug_mode(GtkPspell *gtkpspell, const char *themode)
 {
        gint result;
+       gint mode = PSPELL_FASTMODE;
        g_return_if_fail(gtkpspell);
        g_return_if_fail(gtkpspell->gtkpspeller);
        g_return_if_fail(themode);
 
-       if (!strcmp(themode, _("Fast Mode"))) {
-               result = gtkpspell_set_sug_mode(gtkpspell, PSPELL_FASTMODE);
-       } else if (!strcmp(themode,_("Normal Mode"))) {
-               result = gtkpspell_set_sug_mode(gtkpspell, PSPELL_NORMALMODE);
-       } else if (!strcmp( themode,_("Bad Spellers Mode"))) {
-               result = gtkpspell_set_sug_mode(gtkpspell, PSPELL_BADSPELLERMODE);
-       }
+       if (!strcmp(themode,_("Normal Mode")))
+               mode = PSPELL_NORMALMODE;
+       else if (!strcmp( themode,_("Bad Spellers Mode")))
+               mode = PSPELL_BADSPELLERMODE;
+
+       result = gtkpspell_set_sug_mode(gtkpspell, mode);
 
        if(!result) {
                debug_print(_("Pspell: error while changing suggestion mode:%s\n"),
                            gtkpspellcheckers->error_message);
-               gtkpspell_checkers_reset();
+               gtkpspell_checkers_reset_error();
        }
 }
   
@@ -717,10 +730,13 @@ static void set_real_sug_mode(GtkPspell *gtkpspell, const char *themode)
 gboolean gtkpspell_set_sug_mode(GtkPspell *gtkpspell, gint themode)
 {
        PspellConfig *config;
+
        g_return_val_if_fail(gtkpspell, FALSE);
        g_return_val_if_fail(gtkpspell->gtkpspeller, FALSE);
        g_return_val_if_fail(gtkpspell->gtkpspeller->config, FALSE);
 
+       debug_print("Pspell: setting sug mode of gtkpspeller %0x to %d\n",
+                       gtkpspell->gtkpspeller, themode);
        config = gtkpspell->gtkpspeller->config;
        switch (themode) {
                case PSPELL_FASTMODE: 
@@ -804,9 +820,9 @@ static guchar get_text_index_whar(GtkPspell *gtkpspell, int pos)
 
 /* get_word_from_pos () - return the word pointed to. */
 /* Handles correctly the quotes. */
-static gboolean get_word_from_pos(GtkPspell *gtkpspell, int pos, 
-                                  unsigned char* buf,
-                                  int *pstart, int *pend) 
+static gboolean get_word_from_pos(GtkPspell *gtkpspell, gint pos, 
+                                  unsigned char* buf, gint buflen,
+                                  gint *pstart, gint *pend) 
 {
 
        /* TODO : when correcting a word into quotes, change the color of */
@@ -867,88 +883,51 @@ static gboolean get_word_from_pos(GtkPspell *gtkpspell, int pos,
                                break;
        }
                                                
-       if (buf) {
-               for (pos = start; pos < end; pos++) 
-                       buf[pos - start] = get_text_index_whar(gtkpspell, pos);
-               buf[pos - start] = 0;
-       }
-
        if (pstart) 
                *pstart = start;
        if (pend) 
                *pend = end;
 
+       if (buf) {
+               if (end - start < buflen) {
+                       for (pos = start; pos < end; pos++) 
+                               buf[pos - start] = get_text_index_whar(gtkpspell, pos);
+                       buf[pos - start] = 0;
+               } else return FALSE;
+       }
+
        return TRUE;
 }
 
-static gboolean check_at(GtkPspell *gtkpspell, int from_pos) 
+static gboolean check_at(GtkPspell *gtkpspell, gint from_pos) 
 {
-       int           start, end;
-       unsigned char buf[BUFSIZE];
+       gint          start, end;
+       unsigned char buf[GTKPSPELLWORDSIZE];
        GtkSText     *gtktext;
 
        g_return_val_if_fail(from_pos >= 0, FALSE);
     
        gtktext = gtkpspell->gtktext;
 
-       if (!get_word_from_pos(gtkpspell, from_pos, buf, &start, &end))
+       if (!get_word_from_pos(gtkpspell, from_pos, buf, sizeof(buf), 
+                              &start, &end))
                return FALSE;
 
-
        if (misspelled_test(gtkpspell, buf)) {
                strncpy(gtkpspell->theword, buf, GTKPSPELLWORDSIZE - 1);
                gtkpspell->theword[GTKPSPELLWORDSIZE - 1] = 0;
                gtkpspell->start_pos  = start;
                gtkpspell->end_pos    = end;
-               gtkpspell->newword[0] = 0;
                free_suggestions_list(gtkpspell);
 
-               change_color(gtkpspell, start, end, &(gtkpspell->highlight));
-               
+               change_color(gtkpspell, start, end, buf, &(gtkpspell->highlight));
                return TRUE;
        } else {
-               change_color(gtkpspell, start, end, NULL);
+               change_color(gtkpspell, start, end, buf, NULL);
                return FALSE;
        }
 }
 
-static void check_all_cb(GtkWidget *w, GtkPspell *gtkpspell)
-{
-       gtkpspell_check_all(gtkpspell);
-}
-#if 0 /* Old code */
-void gtkpspell_check_all(GtkPspell *gtkpspell) 
-{
-       guint     origpos;
-       guint     pos = 0;
-       guint     len;
-       float     adj_value;
-       GtkSText *gtktext;
-
-       g_return_if_fail(gtkpspell->gtkpspeller->checker);      
-
-       gtktext = gtkpspell->gtktext;
-
-       len = gtk_stext_get_length(gtktext);
-
-       adj_value = gtktext->vadj->value;
-       gtk_stext_freeze(gtktext);
-       origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
-       gtk_editable_set_position(GTK_EDITABLE(gtktext),0);
-       while (pos < len) {
-               while (pos < len && iswordsep(get_text_index_whar(gtkpspell, pos)))
-                       pos++;
-               while (pos < len && !iswordsep(get_text_index_whar(gtkpspell, pos)))
-                       pos++;
-               if (pos > 0)
-                       check_at(gtkpspell, pos - 1);
-       }
-       gtk_stext_thaw(gtktext);
-       gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
-       gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);
-}
-#endif
-
 static gboolean check_next_prev(GtkPspell *gtkpspell, gboolean forward)
 {
        gint pos;
@@ -956,14 +935,13 @@ static gboolean check_next_prev(GtkPspell *gtkpspell, gboolean forward)
        gint maxpos;
        gint direc = -1;
        gboolean misspelled;
-       GdkEvent *event= (GdkEvent *) gtk_get_current_event();
        
        minpos = 0;
-       maxpos = gtkpspell->last_check_pos;
+       maxpos = gtkpspell->end_check_pos;
 
        if (forward) {
                minpos = -1;
-               direc = -direc;
+               direc = 1;
                maxpos--;
        } 
 
@@ -988,7 +966,7 @@ static gboolean check_next_prev(GtkPspell *gtkpspell, gboolean forward)
                gtk_editable_set_position(GTK_EDITABLE(gtkpspell->gtktext),
                                gtkpspell->end_pos);
                gtk_menu_popup(make_sug_menu(gtkpspell), NULL, NULL, 
-                               set_menu_pos, gtkpspell, 0, gdk_event_get_time(event));
+                               set_menu_pos, gtkpspell, 0, GDK_CURRENT_TIME);
        } else {
                reset_theword_data(gtkpspell);
 
@@ -1002,6 +980,7 @@ static gboolean check_next_prev(GtkPspell *gtkpspell, gboolean forward)
 void gtkpspell_check_backwards(GtkPspell *gtkpspell)
 {
        gtkpspell->continue_check = NULL;
+       gtkpspell->end_check_pos = gtk_stext_get_length(GTK_STEXT(gtkpspell->gtktext));
        check_next_prev(gtkpspell, FALSE);
 }
 
@@ -1009,7 +988,7 @@ void gtkpspell_check_forwards_go(GtkPspell *gtkpspell)
 {
 
        gtkpspell->continue_check = NULL;
-       gtkpspell->last_check_pos = gtk_stext_get_length(GTK_STEXT(gtkpspell->gtktext));
+       gtkpspell->end_check_pos = gtk_stext_get_length(GTK_STEXT(gtkpspell->gtktext));
        check_next_prev(gtkpspell, TRUE);
 }
 
@@ -1017,7 +996,7 @@ void gtkpspell_check_all(GtkPspell *gtkpspell)
 {      
        GtkWidget *gtktext;
        
-       gint start, end, pos;
+       gint start, end;
 
        g_return_if_fail(gtkpspell);
        g_return_if_fail(gtkpspell->gtktext);
@@ -1031,12 +1010,20 @@ void gtkpspell_check_all(GtkPspell *gtkpspell)
                start = GTK_EDITABLE(gtktext)->selection_start_pos;
                end   = GTK_EDITABLE(gtktext)->selection_end_pos;
        }
+
+       if (start > end) {
+               gint tmp;
+               tmp   = start;
+               start = end;
+               end   = tmp;
+       }
+               
        
        gtk_editable_set_position(GTK_EDITABLE(gtktext), start);
        gtk_stext_set_point(GTK_STEXT(gtktext), start);
 
        gtkpspell->continue_check = continue_check;
-       gtkpspell->last_check_pos = end;
+       gtkpspell->end_check_pos = end;
 
        gtkpspell->misspelled = check_next_prev(gtkpspell, TRUE);
 
@@ -1047,19 +1034,59 @@ static void continue_check(gpointer *data)
        GtkPspell *gtkpspell = (GtkPspell *) data;
        gint pos = gtk_editable_get_position(GTK_EDITABLE(gtkpspell->gtktext));
        
-       if (pos < gtkpspell->last_check_pos && gtkpspell->misspelled)
+       if (pos < gtkpspell->end_check_pos && gtkpspell->misspelled)
                gtkpspell->misspelled = check_next_prev(gtkpspell, TRUE);
        else
                gtkpspell->continue_check = NULL;
                
 }
 
-static void replace_with_cb(GtkWidget *w, GtkPspell *gtkpspell) 
+void gtkpspell_highlight_all(GtkPspell *gtkpspell) 
+{
+       guint     origpos;
+       guint     pos = 0;
+       guint     len;
+       GtkSText *gtktext;
+       gfloat    adj_value;
+
+       g_return_if_fail(gtkpspell->gtkpspeller->checker);      
+
+       gtktext = gtkpspell->gtktext;
+
+       adj_value = gtktext->vadj->value;
+
+       len = gtk_stext_get_length(gtktext);
+
+       gtk_stext_freeze(gtktext);
+
+       origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
+
+/*     gtk_editable_set_position(GTK_EDITABLE(gtktext), 0);*/
+
+       while (pos < len) {
+               while (pos < len && 
+                      iswordsep(get_text_index_whar(gtkpspell, pos)))
+                       pos++;
+               while (pos < len &&
+                      !iswordsep(get_text_index_whar(gtkpspell, pos)))
+                       pos++;
+               if (pos > 0)
+                       check_at(gtkpspell, pos - 1);
+       }
+       gtk_stext_thaw(gtktext);
+       gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
+       gtk_stext_set_point(GTK_STEXT(gtktext), origpos);
+       gtk_adjustment_set_value(gtktext->vadj, adj_value);
+       /*gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);*/
+}
+
+static void replace_with_supplied_word_cb(GtkWidget *w, GtkPspell *gtkpspell) 
 {
        unsigned char *newword;
        GdkEvent *e= (GdkEvent *) gtk_get_current_event();
-
+       
        newword = gtk_editable_get_chars(GTK_EDITABLE(gtkpspell->replace_entry), 0, -1);
+       
        if (strcmp(newword, gtkpspell->theword)) {
                replace_real_word(gtkpspell, newword);
 
@@ -1069,28 +1096,38 @@ static void replace_with_cb(GtkWidget *w, GtkPspell *gtkpspell)
                                                         gtkpspell->theword, -1, 
                                                         newword, -1);
                }
-               gtkpspell->newword[0] = 0x00;
                gtkpspell->replace_entry = NULL;
        }
+
        g_free(newword);
+
+       set_point_continue(gtkpspell);
 }
 
 
-static void replace_word(GtkWidget *w, GtkPspell *gtkpspell) 
+static void replace_word_cb(GtkWidget *w, gpointer data)
 {
        unsigned char *newword;
+       GtkPspell *gtkpspell = (GtkPspell *) data;
        GdkEvent *e= (GdkEvent *) gtk_get_current_event();
 
+
        gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), (gchar**) &newword);
+
        replace_real_word(gtkpspell, newword);
-       if ((e->type == GDK_KEY_PRESS && ((GdkEventKey *) e)->state & GDK_MOD1_MASK) ||
-           (e->type == GDK_BUTTON_RELEASE && ((GdkEventButton *) e)->state & GDK_MOD1_MASK)) {
+
+       if ((e->type == GDK_KEY_PRESS && 
+           ((GdkEventKey *) e)->state & GDK_MOD1_MASK) ||
+           (e->type == GDK_BUTTON_RELEASE && 
+            ((GdkEventButton *) e)->state & GDK_MOD1_MASK)) {
                pspell_manager_store_replacement(gtkpspell->gtkpspeller->checker, 
                                                 gtkpspell->theword, -1, 
                                                 newword, -1);
        }
-       gtkpspell->newword[0] = 0x00;
+
        gtk_menu_shell_deactivate(GTK_MENU_SHELL(w->parent));
+
+       set_point_continue(gtkpspell);
 }
 
 static void replace_real_word(GtkPspell *gtkpspell, gchar *newword)
@@ -1111,27 +1148,26 @@ static void replace_real_word(GtkPspell *gtkpspell, gchar *newword)
        oldlen  = gtkpspell->end_pos - gtkpspell->start_pos;
        wordlen = strlen(gtkpspell->theword);
 
-       strncpy(gtkpspell->newword, newword, GTKPSPELLWORDSIZE - 1);
-       gtkpspell->newword[GTKPSPELLWORDSIZE-1] = 0x00;
        newlen = strlen(newword); /* FIXME: multybyte characters? */
 
        gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
-                       GTK_SIGNAL_FUNC(entry_insert_cb), 
-                       gtkpspell);
+                                        GTK_SIGNAL_FUNC(entry_insert_cb), 
+                                        gtkpspell);
        gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
-                       GTK_SIGNAL_FUNC(entry_delete_cb), 
-                       gtkpspell);
+                                        GTK_SIGNAL_FUNC(entry_delete_cb), 
+                                        gtkpspell);
+
        gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "delete-text", 
                                gtkpspell->start_pos, gtkpspell->end_pos);
        gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "insert-text", 
                                newword, newlen, &start);
        
        gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
-                       GTK_SIGNAL_FUNC(entry_insert_cb), 
-                       gtkpspell);
+                                          GTK_SIGNAL_FUNC(entry_insert_cb), 
+                                          gtkpspell);
        gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
-                       GTK_SIGNAL_FUNC(entry_delete_cb), 
-                       gtkpspell);
+                                          GTK_SIGNAL_FUNC(entry_delete_cb), 
+                                          gtkpspell);
        
        /* Put the point and the position where we clicked with the mouse */
        /* It seems to be a hack, as I must thaw,freeze,thaw the widget   */
@@ -1139,7 +1175,8 @@ static void replace_real_word(GtkPspell *gtkpspell, gchar *newword)
        /* point & position position. If not, SEGV after the first replacement */
        /* If the new word ends before point, put the point at its end*/
     
-       if (origpos - gtkpspell->start_pos < oldlen && origpos - gtkpspell->start_pos >= 0) {
+       if (origpos - gtkpspell->start_pos < oldlen && 
+           origpos - gtkpspell->start_pos >= 0) {
                /* Original point was in the word. */
                /* Let it there unless point is going to be outside of the word */
                if (origpos - gtkpspell->start_pos >= newlen) {
@@ -1155,60 +1192,73 @@ static void replace_real_word(GtkPspell *gtkpspell, gchar *newword)
        
        gtk_stext_thaw(GTK_STEXT(gtktext));
        gtk_stext_freeze(GTK_STEXT(gtktext));
+
        if (GTK_STEXT(gtktext)->text_len < pos)
                pos = gtk_stext_get_length(GTK_STEXT(gtktext));
+
        gtkpspell->orig_pos = pos;
+
        gtk_editable_set_position(GTK_EDITABLE(gtktext), gtkpspell->orig_pos);
        gtk_stext_set_point(GTK_STEXT(gtktext), 
                            gtk_editable_get_position(GTK_EDITABLE(gtktext)));
+
        gtk_stext_thaw(GTK_STEXT(gtktext));
 }
 
 /* Accept this word for this session */
-
-static void add_word_to_session(GtkWidget *w, GtkPspell *gtkpspell)
+static void add_word_to_session_cb(GtkWidget *w, gpointer data)
 {
        guint     pos;
        GtkSText *gtktext;
-    
+       GtkPspell *gtkpspell = (GtkPspell *) data; 
        gtktext = gtkpspell->gtktext;
 
        gtk_stext_freeze(GTK_STEXT(gtktext));
 
        pos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
     
-       pspell_manager_add_to_session(gtkpspell->gtkpspeller->checker,gtkpspell->theword, strlen(gtkpspell->theword));
+       pspell_manager_add_to_session(gtkpspell->gtkpspeller->checker,
+                                     gtkpspell->theword, 
+                                     strlen(gtkpspell->theword));
 
        check_at(gtkpspell, gtkpspell->start_pos);
 
        gtk_stext_thaw(gtkpspell->gtktext);
-       gtk_menu_shell_deactivate(GTK_MENU_SHELL(w->parent));
+
+       gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
+
+       set_point_continue(gtkpspell);
 }
 
-/* add_word_to_personal() - add word to personal dict. */
-static void add_word_to_personal(GtkWidget *w, GtkPspell *gtkpspell)
+/* add_word_to_personal_cb() - add word to personal dict. */
+static void add_word_to_personal_cb(GtkWidget *w, gpointer data)
 {
        GtkSText *gtktext;
-    
+       GtkPspell *gtkpspell = (GtkPspell *) data; 
        gtktext = gtkpspell->gtktext;
 
        gtk_stext_freeze(GTK_STEXT(gtktext));
     
-       pspell_manager_add_to_personal(gtkpspell->gtkpspeller->checker,gtkpspell->theword, strlen(gtkpspell->theword));
+       pspell_manager_add_to_personal(gtkpspell->gtkpspeller->checker,
+                                      gtkpspell->theword,
+                                      strlen(gtkpspell->theword));
     
        check_at(gtkpspell, gtkpspell->start_pos);
 
        gtk_stext_thaw(gtkpspell->gtktext);
-       gtk_menu_shell_deactivate(GTK_MENU_SHELL(w->parent));
+
+       gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
+       set_point_continue(gtkpspell);
 }
 
-static void deactivate_menu(GtkWidget *w, gpointer data)
+static void deactivate_sug_menu_cb(GtkObject *w, gpointer data)
 {
-       GtkMenuShell *menu_shell = (GtkMenuShell *) data;
+       GtkMenuShell *menu_shell = GTK_MENU_SHELL(data);
+       debug_print("Destroying %0x\n", w);
        gtk_menu_shell_deactivate(menu_shell);
 }
 
-static void replace_with(GtkWidget *w, GtkPspell *gtkpspell)
+static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
 {
        GtkWidget *dialog;
        GtkWidget *label;
@@ -1218,19 +1268,17 @@ static void replace_with(GtkWidget *w, GtkPspell *gtkpspell)
        GtkWidget *cancel_button;
        gchar *thelabel;
        gint xx, yy;
+       GtkPspell *gtkpspell = (GtkPspell *) data;
 
-       gdk_window_get_origin(GTK_WIDGET(w->parent)->window, &xx, &yy);
+       gdk_window_get_origin((GTK_WIDGET(w)->parent)->window, &xx, &yy);
 
-       gtk_widget_hide(w->parent);
+       gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
 
        dialog = gtk_dialog_new();
        gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
        gtk_window_set_title(GTK_WINDOW(dialog),_("Replace unknown word"));
        gtk_widget_set_uposition(dialog, xx, yy);
 
-       gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
-                         GTK_SIGNAL_FUNC(deactivate_menu), 
-                         w->parent);
        gtk_signal_connect_object(GTK_OBJECT(dialog), "destroy",
                                  GTK_SIGNAL_FUNC(gtk_widget_destroy), 
                                  GTK_OBJECT(dialog));
@@ -1249,20 +1297,22 @@ static void replace_with(GtkWidget *w, GtkPspell *gtkpspell)
        gtk_entry_set_text(GTK_ENTRY(entry), gtkpspell->theword);
        gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
        gtk_signal_connect(GTK_OBJECT(entry), "activate",
-                          GTK_SIGNAL_FUNC(replace_with_cb), 
+                          GTK_SIGNAL_FUNC(replace_with_supplied_word_cb), 
                           gtkpspell);
        gtk_signal_connect_object(GTK_OBJECT(entry), "activate",
                           GTK_SIGNAL_FUNC(gtk_widget_destroy), 
                           GTK_OBJECT(dialog));
        gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
 
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 0);
+       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, 
+                          TRUE, 0);
        if (!gtkpspell->gtkpspeller->ispell) {
                label = gtk_label_new(_("Holding down MOD1 key while pressing Enter\nwill learn from mistake.\n"));
                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(GTK_DIALOG(dialog)->vbox), label, 
+                                  TRUE, TRUE, 0);
        }
 
        hbox = gtk_hbox_new(TRUE, 0);
@@ -1270,17 +1320,17 @@ static void replace_with(GtkWidget *w, GtkPspell *gtkpspell)
        ok_button = gtk_button_new_with_label(_("OK"));
        gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 8);
        gtk_signal_connect(GTK_OBJECT(ok_button), "clicked",
-                       GTK_SIGNAL_FUNC(replace_with_cb), 
-                       gtkpspell);
+                          GTK_SIGNAL_FUNC(replace_with_supplied_word_cb), 
+                          gtkpspell);
        gtk_signal_connect_object(GTK_OBJECT(ok_button), "clicked",
-                       GTK_SIGNAL_FUNC(gtk_widget_destroy), 
-                       GTK_OBJECT(dialog));
+                                 GTK_SIGNAL_FUNC(gtk_widget_destroy), 
+                                 GTK_OBJECT(dialog));
 
        cancel_button = gtk_button_new_with_label(_("Cancel"));
        gtk_box_pack_start(GTK_BOX(hbox), cancel_button, TRUE, TRUE, 8);
        gtk_signal_connect_object(GTK_OBJECT(cancel_button), "clicked",
-                       GTK_SIGNAL_FUNC(gtk_widget_destroy), 
-                       GTK_OBJECT(dialog));
+                                 GTK_SIGNAL_FUNC(gtk_widget_destroy), 
+                                 GTK_OBJECT(dialog));
 
        gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), hbox);
 
@@ -1293,34 +1343,42 @@ static void replace_with(GtkWidget *w, GtkPspell *gtkpspell)
 
 void gtkpspell_uncheck_all(GtkPspell * gtkpspell) 
 {
-       int origpos;
-       unsigned char *text;
-       float adj_value;
+       gint      origpos;
+       gchar    *text;
+       gfloat    adj_value;
        GtkSText *gtktext;
        
-       gtktext=gtkpspell->gtktext;
+       gtktext = gtkpspell->gtktext;
 
        adj_value = gtktext->vadj->value;
+
        gtk_stext_freeze(gtktext);
+
        origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
+
        text = gtk_editable_get_chars(GTK_EDITABLE(gtktext), 0, -1);
+
        gtk_stext_set_point(gtktext, 0);
        gtk_stext_forward_delete(gtktext, gtk_stext_get_length(gtktext));
        gtk_stext_insert(gtktext, NULL, NULL, NULL, text, strlen(text));
-       gtk_stext_thaw(gtktext);
 
-       g_free(text);
+       gtk_stext_thaw(gtktext);
 
        gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
+       gtk_stext_set_point(gtktext, origpos);
        gtk_adjustment_set_value(gtktext->vadj, adj_value);
+
+       g_free(text);
+
 }
 
-static void toggle_check_while_typing(GtkWidget *w, gpointer data)
+static void toggle_check_while_typing_cb(GtkWidget *w, gpointer data)
 {
        GtkPspell *gtkpspell = (GtkPspell *) data;
 
        gtkpspell->check_while_typing = gtkpspell->check_while_typing == FALSE;
-       gtkpspell_uncheck_all(gtkpspell);
+       if (!gtkpspell->check_while_typing)
+               gtkpspell_uncheck_all(gtkpspell);
 
        if (gtkpspell->config_menu)
                populate_submenu(gtkpspell, gtkpspell->config_menu);
@@ -1362,42 +1420,49 @@ GSList *gtkpspell_get_dictionary_list(const gchar *pspell_path, gint refresh)
 #warning TODO: no directory change
 #endif
        dict_path = g_strdup(pspell_path);
-       prevdir = g_get_current_dir();
+       prevdir   = g_get_current_dir();
        if (chdir(dict_path) <0) {
-               debug_print(_("Error when searching for dictionaries:\n%s\n"),
-                                         g_strerror(errno));
+               debug_print(_("Pspell: error when searching for dictionaries:\n%s\n"),
+                           g_strerror(errno));
                g_free(prevdir);
                g_free(dict_path);
                gtkpspellcheckers->dictionary_list = create_empty_dictionary_list();
                return gtkpspellcheckers->dictionary_list; 
        }
 
-       debug_print(_("Checking for dictionaries in %s\n"), dict_path);
+       debug_print(_("Pspell: checking for dictionaries in %s\n"), dict_path);
 
        if (NULL != (dir = opendir("."))) {
                while (NULL != (ent = readdir(dir))) {
                        /* search for pwli */
-                       if ((NULL != (tmp = strstr2(ent->d_name, ".pwli"))) && (tmp[5] == 0x00)) {
-                               g_snprintf(tmpname, BUFSIZE, "%s%s", G_DIR_SEPARATOR_S, ent->d_name);
+                       if ((NULL != (tmp = strstr2(ent->d_name, ".pwli"))) && 
+                           (tmp[5] == 0x00)) {
+                               g_snprintf(tmpname, BUFSIZE, "%s%s", 
+                                          G_DIR_SEPARATOR_S, ent->d_name);
                                tmpname[MIN(tmp - ent->d_name + 1, BUFSIZE-1)] = 0x00;
                                dict = g_new0(Dictionary, 1);
-                               dict->fullname = g_strdup_printf("%s%s", dict_path, tmpname);
-                               dict->dictname = strrchr(dict->fullname, G_DIR_SEPARATOR) + 1;
+                               dict->fullname = g_strdup_printf("%s%s", 
+                                                                dict_path, 
+                                                                tmpname);
+                               dict->dictname = strrchr(dict->fullname, 
+                                                        G_DIR_SEPARATOR) + 1;
                                dict->encoding = NULL;
-                               debug_print(_("Found dictionary %s %s\n"), dict->fullname, dict->dictname);
-                               list = g_slist_insert_sorted(list, dict, (GCompareFunc) compare_dict);
+                               debug_print(_("Pspell: found dictionary %s %s\n"),
+                                           dict->fullname, dict->dictname);
+                               list = g_slist_insert_sorted(list, dict,
+                                               (GCompareFunc) compare_dict);
                        }
                }                       
                closedir(dir);
        }
        else {
-               debug_print(_("Error when searching for dictionaries.\nNo dictionary found.\n(%s)"), 
-                                         g_strerror(errno));
+               debug_print(_("Pspell: error when searching for dictionaries.\nNo dictionary found.\n(%s)"), 
+                           g_strerror(errno));
                list = create_empty_dictionary_list();
        }
         if(list==NULL){
                
-               debug_print(_("Error when searching for dictionaries.\nNo dictionary found."));
+               debug_print(_("Pspell: error when searching for dictionaries.\nNo dictionary found."));
                list = create_empty_dictionary_list();
        }
        chdir(prevdir);
@@ -1523,7 +1588,7 @@ gint gtkpspell_get_sugmode_from_option_menu(GtkOptionMenu *optmenu)
        return sugmode;
        
 }
-
+#if 0 /* Experimenal */
 void gtkpspell_set_primary_dict(GtkPspell *gtkpspell, gchar *dict, gchar *encoding)
 {
        g_return_if_fail(gtkpspell);
@@ -1584,6 +1649,7 @@ gboolean gtkpspell_use_secondary(GtkPspell *gtkpspell)
 
        return gtkpspell_use_dict(gtkpspell, gtkpspell->dict2);
 }
+#endif
 
 /*****************************************************************************/
 
@@ -1604,7 +1670,7 @@ static void popup_menu(GtkPspell *gtkpspell, GdkEventButton *eb)
                        if (misspelled_suggest(gtkpspell, gtkpspell->theword)) {
                                gtk_menu_popup(make_sug_menu(gtkpspell), 
                                               NULL, NULL, NULL, NULL,
-                                              eb->button, eb->time);
+                                              eb->button, GDK_CURRENT_TIME);
                                
                                return;
                        }
@@ -1616,7 +1682,7 @@ static void popup_menu(GtkPspell *gtkpspell, GdkEventButton *eb)
        }
 
        gtk_menu_popup(make_config_menu(gtkpspell),NULL,NULL,NULL,NULL,
-                      eb->button,eb->time);
+                      eb->button, GDK_CURRENT_TIME);
 }
 
 /* make_sug_menu() - Add menus to accept this word for this session and to add it to 
@@ -1634,9 +1700,12 @@ static GtkMenu *make_sug_menu(GtkPspell *gtkpspell)
 
        accel = gtk_accel_group_new();
        menu = gtk_menu_new(); 
-       
-       gtk_signal_connect(GTK_OBJECT(menu), "deactivate",
-               GTK_SIGNAL_FUNC(deactivate_menu_cb), gtkpspell);
+
+       if (gtkpspell->sug_menu)
+               gtk_widget_destroy(gtkpspell->sug_menu);
+
+       gtkpspell->sug_menu = menu;     
+
        gtk_signal_connect(GTK_OBJECT(menu), "cancel",
                GTK_SIGNAL_FUNC(cancel_menu_cb), gtkpspell);
 
@@ -1656,33 +1725,30 @@ static GtkMenu *make_sug_menu(GtkPspell *gtkpspell)
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu), item);
         gtk_signal_connect(GTK_OBJECT(item), "activate",
-                          GTK_SIGNAL_FUNC(add_word_to_session), 
+                          GTK_SIGNAL_FUNC(add_word_to_session_cb), 
                           gtkpspell);
-       gtk_accel_group_add(accel, GDK_space, GDK_MOD1_MASK, 
-                           GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE, 
-                           GTK_OBJECT(item), "activate");
+       gtk_widget_add_accelerator(item, "activate", accel, GDK_space, GDK_MOD1_MASK,
+                                  GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
 
        item = gtk_menu_item_new_with_label(_("Add to personal dictionary"));
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu), item);
         gtk_signal_connect(GTK_OBJECT(item), "activate",
-                          GTK_SIGNAL_FUNC(add_word_to_personal), 
+                          GTK_SIGNAL_FUNC(add_word_to_personal_cb), 
                           gtkpspell);
-       gtk_accel_group_add(accel, GDK_Return, GDK_MOD1_MASK, 
-                           GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE, 
-                           GTK_OBJECT(item), "activate");
-       
+       gtk_widget_add_accelerator(item, "activate", accel, GDK_Return, GDK_MOD1_MASK,
+                                  GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
+
         item = gtk_menu_item_new_with_label(_("Replace with..."));
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu), item);
         gtk_signal_connect(GTK_OBJECT(item), "activate",
-                          GTK_SIGNAL_FUNC(replace_with), 
+                          GTK_SIGNAL_FUNC(replace_with_create_dialog_cb), 
                           gtkpspell);
-       gtk_accel_group_add(accel, 'r', 0, 
-                           GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE, 
-                           GTK_OBJECT(item), "activate");
-       
-        item = gtk_menu_item_new();
+       gtk_widget_add_accelerator(item, "activate", accel, GDK_R, 0,
+                                  GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
+
+       item = gtk_menu_item_new();
         gtk_widget_show(item);
         gtk_menu_append(GTK_MENU(menu), item);
 
@@ -1707,32 +1773,41 @@ static GtkMenu *make_sug_menu(GtkPspell *gtkpspell)
                                l = l->next;
                        } else if (count > MENUCOUNT) {
                                count -= MENUCOUNT;
+
                                item = gtk_menu_item_new_with_label(_("More..."));
                                gtk_widget_show(item);
                                gtk_menu_append(GTK_MENU(curmenu), item);
+
                                curmenu = gtk_menu_new();
                                gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
                        }
+
                        item = gtk_menu_item_new_with_label((unsigned char*)l->data);
                        gtk_widget_show(item);
                        gtk_menu_append(GTK_MENU(curmenu), item);
                        gtk_signal_connect(GTK_OBJECT(item), "activate",
-                                          GTK_SIGNAL_FUNC(replace_word), gtkpspell);
-                       if (count <= MENUCOUNT) {
-                               gtk_accel_group_add(accel, 'a' + count, 0, 
-                                       GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE, 
-                                       GTK_OBJECT(item), "activate");
-                               gtk_accel_group_add(accel, 'a' + count, 
-                                       GDK_MOD1_MASK, GTK_ACCEL_LOCKED, 
-                                       GTK_OBJECT(item), "activate");
+                                          GTK_SIGNAL_FUNC(replace_word_cb), gtkpspell);
+
+                       if (curmenu == menu && count < MENUCOUNT) {
+                               gtk_widget_add_accelerator(item, "activate",
+                                                          accel,
+                                                          GDK_A + count, 0,
+                                                          GTK_ACCEL_LOCKED | 
+                                                          GTK_ACCEL_VISIBLE);
+                               gtk_widget_add_accelerator(item, "activate", 
+                                                          accel,
+                                                          GDK_A + count, 
+                                                          GDK_MOD1_MASK,
+                                                          GTK_ACCEL_LOCKED);
                                }
 
-
                        count++;
+
                } while ((l = l->next) != NULL);
        }
-       
+
        gtk_accel_group_attach(accel, GTK_OBJECT(menu));
+       gtk_accel_group_unref(accel);
        
        return GTK_MENU(menu);
 }
@@ -1748,8 +1823,7 @@ static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu)
                GList *amenu, *alist;
                for (amenu = (GTK_MENU_SHELL(menu)->children); amenu; ) {
                        alist = amenu->next;
-                       item = GTK_WIDGET(amenu->data);
-                       gtk_widget_destroy(item);
+                       gtk_widget_destroy(GTK_WIDGET(amenu->data));
                        amenu = alist;
                }
        }
@@ -1772,8 +1846,8 @@ static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu)
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),TRUE);
        else
                gtk_signal_connect(GTK_OBJECT(item), "activate",
-                               GTK_SIGNAL_FUNC(set_sug_mode_cb),
-                               gtkpspell);
+                                  GTK_SIGNAL_FUNC(set_sug_mode_cb),
+                                  gtkpspell);
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu), item);
 
@@ -1784,8 +1858,8 @@ static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu)
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
        else
                gtk_signal_connect(GTK_OBJECT(item), "activate",
-                               GTK_SIGNAL_FUNC(set_sug_mode_cb),
-                               gtkpspell);
+                                  GTK_SIGNAL_FUNC(set_sug_mode_cb),
+                                  gtkpspell);
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu),item);
 
@@ -1796,8 +1870,8 @@ static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu)
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
        else
                gtk_signal_connect(GTK_OBJECT(item), "activate",
-                               GTK_SIGNAL_FUNC(set_sug_mode_cb),
-                               gtkpspell);
+                                  GTK_SIGNAL_FUNC(set_sug_mode_cb),
+                                  gtkpspell);
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu), item);
        
@@ -1811,7 +1885,7 @@ static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu)
        else    
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), FALSE);
        gtk_signal_connect(GTK_OBJECT(item), "activate",
-                          GTK_SIGNAL_FUNC(toggle_check_while_typing),
+                          GTK_SIGNAL_FUNC(toggle_check_while_typing_cb),
                           gtkpspell);
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu), item);
@@ -1878,21 +1952,26 @@ static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu)
 
 static GtkMenu *make_config_menu(GtkPspell *gtkpspell)
 {
-       GtkWidget *menu, *item, *submenu;
-       gint ispell = gtkpspell->gtkpspeller->ispell;
-  
-       menu = gtk_menu_new();
-       
-       populate_submenu(gtkpspell, menu);
+       if (!gtkpspell->popup_config_menu)
+               gtkpspell->popup_config_menu = gtk_menu_new();
 
-        return GTK_MENU(menu);
+       debug_print("Pspell: creating/using popup_config_menu %0x\n", 
+                       gtkpspell->popup_config_menu);
+       populate_submenu(gtkpspell, gtkpspell->popup_config_menu);
+
+        return GTK_MENU(gtkpspell->popup_config_menu);
 }
 
 void gtkpspell_populate_submenu(GtkPspell *gtkpspell, GtkWidget *menuitem)
 {
        GtkWidget *menu;
+
        menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
+       
+       debug_print("Pspell: using config menu %0x\n", 
+                       gtkpspell->popup_config_menu);
        populate_submenu(gtkpspell, menu);
+       
        gtkpspell->config_menu = menu;
        
 }
@@ -1932,27 +2011,11 @@ static void set_menu_pos(GtkMenu *menu, gint *x, gint *y, gpointer data)
 /*************************************************************************/
 /* Menu call backs */
 
-static gboolean deactivate_menu_cb(GtkWidget *w, gpointer *data)
-{
-       GtkPspell *gtkpspell = (GtkPspell *) data;
-       GtkSText *gtktext;
-       gtktext = gtkpspell->gtktext;
-
-       gtk_stext_freeze(gtktext);
-       gtk_editable_set_position(GTK_EDITABLE(gtktext),gtkpspell->orig_pos);
-       gtk_stext_set_point(gtktext, gtkpspell->orig_pos);
-       gtk_stext_thaw(gtktext);
-
-       if (gtkpspell->continue_check)
-               gtkpspell->continue_check((gpointer *) gtkpspell);
-
-       return FALSE;
-}
-
 static gboolean cancel_menu_cb(GtkMenuShell *w, gpointer data)
 {
        GtkPspell *gtkpspell = (GtkPspell *) data;
        gtkpspell->continue_check = NULL;
+       set_point_continue(gtkpspell);
        return FALSE;
        
 }
@@ -2000,18 +2063,32 @@ static void change_dict_cb(GtkWidget *w, GtkPspell *gtkpspell)
 /******************************************************************************/
 /* Misc. helper functions */
 
-static void allocate_color(GtkPspell *gtkpspell)
+static void set_point_continue(GtkPspell *gtkpspell)
+{
+       GtkSText  *gtktext;
+
+       gtktext = gtkpspell->gtktext;
+
+       gtk_stext_freeze(gtktext);
+       gtk_editable_set_position(GTK_EDITABLE(gtktext),gtkpspell->orig_pos);
+       gtk_stext_set_point(gtktext, gtkpspell->orig_pos);
+       gtk_stext_thaw(gtktext);
+
+       if (gtkpspell->continue_check)
+               gtkpspell->continue_check((gpointer *) gtkpspell);
+}
+
+static void allocate_color(GtkPspell *gtkpspell, gint rgbvalue)
 {
        GdkColormap *gc;
        GdkColor *color = &(gtkpspell->highlight);
-       gint rgbvalue   = prefs_common.misspelled_col;
 
        gc = gtk_widget_get_colormap(GTK_WIDGET(gtkpspell->gtktext));
 
        if (gtkpspell->highlight.pixel)
                gdk_colormap_free_colors(gc, &(gtkpspell->highlight), 1);
 
-       /* Shameless copy from Sylpheed gtkutils.c */
+       /* Shameless copy from Sylpheed's gtkutils.c */
        color->pixel = 0L;
        color->red   = (int) (((gdouble)((rgbvalue & 0xff0000) >> 16) / 255.0) * 65535.0);
        color->green = (int) (((gdouble)((rgbvalue & 0x00ff00) >>  8) / 255.0) * 65535.0);
@@ -2021,10 +2098,10 @@ static void allocate_color(GtkPspell *gtkpspell)
 }
 
 static void change_color(GtkPspell * gtkpspell, 
-                        int start, int end, 
+                        gint start, gint end,
+                        gchar *newtext,
                          GdkColor *color) 
 {
-       char     *newtext;
        GtkSText *gtktext;
 
        g_return_if_fail(start < end);
@@ -2032,13 +2109,10 @@ static void change_color(GtkPspell * gtkpspell,
        gtktext = gtkpspell->gtktext;
     
        gtk_stext_freeze(gtktext);
-       newtext = gtk_editable_get_chars(GTK_EDITABLE(gtktext), start, end);
        if (newtext) {
                gtk_stext_set_point(gtktext, start);
                gtk_stext_forward_delete(gtktext, end - start);
-
                gtk_stext_insert(gtktext, NULL, color, NULL, newtext, end - start);
-               g_free(newtext);
        }
        gtk_stext_thaw(gtktext);
 }
@@ -2127,7 +2201,6 @@ static void reset_theword_data(GtkPspell *gtkpspell)
        gtkpspell->end_pos       =  0;
        gtkpspell->theword[0]    =  0;
        gtkpspell->max_sug       = -1;
-       gtkpspell->newword[0]    =  0;
 
        free_suggestions_list(gtkpspell);
 }
@@ -2146,11 +2219,9 @@ static gint find_gtkpspeller(gconstpointer aa, gconstpointer bb)
        Dictionary *a = ((GtkPspeller *) aa)->dictionary;
        Dictionary *b = ((GtkPspeller *) bb)->dictionary;
 
-       if (!a || !b)
-               return 1;
-
-       if (strcmp(a->fullname, b->fullname) == 0
-           && a->encoding && b->encoding)
+       if (a && b && a->fullname && b->fullname  &&
+           strcmp(a->fullname, b->fullname) == 0 &&
+           a->encoding && b->encoding)
                return strcmp(a->encoding, b->encoding);
 
        return 1;
index 8dcb99cf2cc6da7489a3bdafd2b9d5088f4aa27d..5f98d81eb943d21dbbfe7b43e0d1c356bef5e0fd 100644 (file)
 #define PSPELL_BADSPELLERMODE 3
 
 typedef struct _GtkPspellCheckers {
-       GSList *        checkers;
-       GSList *        dictionary_list;
-       gchar *         error_message;
+       GSList          *checkers;
+       GSList          *dictionary_list;
+       gchar           *error_message;
 } GtkPspellCheckers;
 
 typedef struct _Dictionary {
-       gchar *         fullname;
-       gchar *         dictname; /* dictname points into fullname */
-       gchar *         encoding;
+       gchar           *fullname;
+       gchar           *dictname; /* dictname points into fullname */
+       gchar           *encoding;
 } Dictionary;
 
 typedef struct _GtkPspeller {
@@ -64,33 +64,34 @@ typedef void (*ContCheckFunc)       (gpointer *gtkpspell);
 
 #define GTKPSPELLWORDSIZE 1024
 typedef struct _GtkPspell {
-       GtkPspeller *   gtkpspeller;
-       gchar           theword[GTKPSPELLWORDSIZE];
-       gchar           newword[GTKPSPELLWORDSIZE];
-       gint            start_pos;
-       gint            end_pos;
-        gint           orig_pos;
-       gint            last_check_pos;
-       gboolean        misspelled;
-       gboolean        check_while_typing;
-
-       ContCheckFunc   continue_check; 
-
-       Dictionary *    dict1;
-       Dictionary *    dict2;
-
-       GtkWidget *     gui;
-       gpointer *      compose;
-       
-       GtkWidget*      config_menu;
-       GtkWidget *     replace_entry;
-
-       gint            default_sug_mode;
-       gint            max_sug;
-       GList *         suggestions_list;
-
-       GtkSText *      gtktext;
-       GdkColor        highlight;
+       GtkPspeller     *gtkpspeller;
+       gchar            theword[GTKPSPELLWORDSIZE];
+       gint             start_pos;
+       gint             end_pos;
+        gint            orig_pos;
+       gint             end_check_pos;
+       gboolean         misspelled;
+       gboolean         check_while_typing;
+
+       ContCheckFunc    continue_check; 
+#if 0
+       Dictionary      *dict1;
+       Dictionary      *dict2;
+
+       GtkWidget       *gui;
+       gpointer        *compose;
+#endif
+       GtkWidget       *config_menu;
+       GtkWidget       *popup_config_menu;
+       GtkWidget       *sug_menu;
+       GtkWidget       *replace_entry;
+
+       gint             default_sug_mode;
+       gint             max_sug;
+       GList           *suggestions_list;
+
+       GtkSText        *gtktext;
+       GdkColor         highlight;
 } GtkPspell;
 
 typedef PspellConfig GtkPspellConfig;
@@ -101,10 +102,11 @@ GtkPspellCheckers*        gtkpspell_checkers_new          ();
 
 GtkPspellCheckers*     gtkpspell_checkers_delete       ();
 
-void                   gtkpspell_checkers_reset        ();
+void                   gtkpspell_checkers_reset_error  ();
 
 GtkPspell*             gtkpspell_new                   (const gchar *dictionary, 
                                                         const gchar *encoding,
+                                                        gint  misspelled_color,
                                                         gboolean check_while_typing,  
                                                         GtkSText *gtktext);
 
@@ -127,6 +129,7 @@ void                        gtkpspell_check_backwards       (GtkPspell *gtkpspell);
 
 void                   gtkpspell_check_all             (GtkPspell *gtkpspell);
 void                   gtkpspell_uncheck_all           (GtkPspell *gtkpspell);
+void                   gtkpspell_highlight_all         (GtkPspell *gtkpspell);
 
 void                   gtkpspell_populate_submenu      (GtkPspell *gtkpspell, 
                                                         GtkWidget *menuitem);