2007-10-30 [paul] 3.0.2cvs107
[claws.git] / src / gtk / gtkaspell.c
index efaf39535606e01abe3546576a71054d9c5f2a10..fd146df6a4597510bec37fb213c53203e55135ab 100644 (file)
@@ -5,7 +5,7 @@
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 3 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 /*
  * Stuphead: (C) 2000,2001 Grigroy Bakunov, Sergey Pinaev
  * Adapted for Sylpheed (Claws) (c) 2001-2002 by Hiroyuki Yamamoto & 
- * The Sylpheed Claws Team.
+ * The Claws Mail Team.
  * Adapted for pspell (c) 2001-2002 Melvin Hadasht
  * Adapted for GNU/aspell (c) 2002 Melvin Hadasht
  */
@@ -28,7 +27,7 @@
 #  include "config.h"
 #endif
 
-#if USE_ASPELL
+#ifdef USE_ASPELL
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -44,6 +43,9 @@
 #include <time.h>
 #include <dirent.h>
 
+#include <glib.h>
+#include <glib/gi18n.h>
+
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 #include <gtk/gtkoptionmenu.h>
 #include <gtk/gtkmenuitem.h>
 #include <gdk/gdkkeysyms.h>
 
-#include "intl.h"
-#include "gtkstext.h"
+#include <aspell.h>
+
 #include "utils.h"
+#include "codeconv.h"
+#include "alertpanel.h"
 #include "gtkaspell.h"
+#include "gtk/gtkutils.h"
+#include "gtk/combobox.h"
+
+#define ASPELL_FASTMODE       1
+#define ASPELL_NORMALMODE     2
+#define ASPELL_BADSPELLERMODE 3
+
+#define GTKASPELLWORDSIZE 1024
 
 /* size of the text buffer used in various word-processing routines. */
 #define BUFSIZE 1024
        RETURN_FALSE_IF_CONFIG_ERROR();                      \
        }
 
+enum {
+       SET_GTKASPELL_NAME      = 0,
+       SET_GTKASPELL_FULLNAME  = 1,
+       SET_GTKASPELL_SIZE
+};
+
+typedef struct _GtkAspellCheckers {
+       GSList          *checkers;
+       GSList          *dictionary_list;
+       gchar           *error_message;
+} GtkAspellCheckers;
+
+typedef struct _Dictionary {
+       gchar *fullname;
+       gchar *dictname;
+       gchar *encoding;
+} Dictionary;
+
+typedef struct _GtkAspeller {
+       Dictionary      *dictionary;
+       gint             sug_mode;
+       AspellConfig    *config;
+       AspellSpeller   *checker;
+} GtkAspeller;
+
+typedef void (*ContCheckFunc) (gpointer *gtkaspell);
+
+struct _GtkAspell
+{
+       GtkAspeller     *gtkaspeller;
+       GtkAspeller     *alternate_speller;
+       gchar           *dictionary_path;
+       gchar            theword[GTKASPELLWORDSIZE];
+       gint             start_pos;
+       gint             end_pos;
+        gint            orig_pos;
+       gint             end_check_pos;
+       gboolean         misspelled;
+       gboolean         check_while_typing;
+       gboolean         recheck_when_changing_dict;
+       gboolean         use_alternate;
+       gboolean         use_both_dicts;
+
+       ContCheckFunc    continue_check; 
+
+       GtkWidget       *replace_entry;
+       GtkWidget       *parent_window;
+
+       gint             default_sug_mode;
+       gint             max_sug;
+       GList           *suggestions_list;
+
+       GtkTextView     *gtktext;
+       GdkColor         highlight;
+       GtkAccelGroup   *accel_group;
+       void            (*menu_changed_cb)(void *data);
+       void            *menu_changed_data;
+};
+
+typedef AspellConfig GtkAspellConfig;
+
 /******************************************************************************/
 
-GtkAspellCheckers *gtkaspellcheckers;
+static GtkAspellCheckers *gtkaspellcheckers;
 
 /* Error message storage */
 static void gtkaspell_checkers_error_message   (gchar          *message);
 
 /* Callbacks */
-static void entry_insert_cb                    (GtkSText       *gtktext, 
+static void entry_insert_cb                    (GtkTextBuffer  *textbuf,
+                                                GtkTextIter    *iter,
                                                 gchar          *newtext, 
-                                                guint           len, 
-                                                guint          *ppos, 
+                                                gint           len,
                                                 GtkAspell      *gtkaspell);
-static void entry_delete_cb                    (GtkSText       *gtktext, 
-                                                gint            start, 
-                                                gint            end,
+static void entry_delete_cb                    (GtkTextBuffer  *textbuf,
+                                                GtkTextIter    *startiter,
+                                                GtkTextIter    *enditer,
                                                 GtkAspell      *gtkaspell);
-static gint button_press_intercept_cb          (GtkSText       *gtktext, 
+/*static gint button_press_intercept_cb                (GtkTextView    *gtktext,
                                                 GdkEvent       *e, 
                                                 GtkAspell      *gtkaspell);
-
+*/
+static void button_press_intercept_cb(GtkTextView *gtktext,
+                       GtkMenu *menu, GtkAspell *gtkaspell);
+                       
 /* Checker creation */
 static GtkAspeller* gtkaspeller_new            (Dictionary     *dict);
 static GtkAspeller* gtkaspeller_real_new       (Dictionary     *dict);
@@ -108,6 +184,8 @@ static gint                 set_dictionary                  (AspellConfig *config,
                                                         Dictionary *dict);
 static void            set_sug_mode_cb                 (GtkMenuItem *w, 
                                                         GtkAspell *gtkaspell);
+static void            set_use_both_cb                 (GtkMenuItem *w, 
+                                                        GtkAspell *gtkaspell);
 static void            set_real_sug_mode               (GtkAspell *gtkaspell, 
                                                         const char *themode);
 
@@ -117,7 +195,7 @@ static gboolean check_at                    (GtkAspell      *gtkaspell,
 static gboolean        check_next_prev                 (GtkAspell      *gtkaspell, 
                                                 gboolean        forward);
 static GList* misspelled_suggest               (GtkAspell      *gtkaspell, 
-                                                guchar         *word);
+                                                gchar          *word);
 static void add_word_to_session_cb             (GtkWidget      *w, 
                                                 gpointer        data);
 static void add_word_to_personal_cb            (GtkWidget      *w, 
@@ -137,19 +215,18 @@ static void toggle_check_while_typing_cb  (GtkWidget      *w,
                                                 gpointer        data);
 
 /* Menu creation */
-static void popup_menu                         (GtkAspell      *gtkaspell, 
-                                                GdkEventButton *eb);
-static GtkMenu*        make_sug_menu                   (GtkAspell      *gtkaspell);
-static void populate_submenu                   (GtkAspell      *gtkaspell, 
-                                                GtkWidget      *menu);
-static GtkMenu*        make_config_menu                (GtkAspell      *gtkaspell);
+static GSList* make_sug_menu                   (GtkAspell      *gtkaspell);
+static GSList * populate_submenu               (GtkAspell      *gtkaspell);
+GSList*        gtkaspell_make_config_menu              (GtkAspell      *gtkaspell);
 static void set_menu_pos                       (GtkMenu        *menu, 
                                                 gint           *x, 
                                                 gint           *y, 
+                                                gboolean       *push_in,
                                                 gpointer        data);
 /* Other menu callbacks */
-static gboolean cancel_menu_cb                 (GtkMenuShell   *w,
-                                                gpointer        data);
+static gboolean aspell_key_pressed             (GtkWidget *widget,
+                                                GdkEventKey *event,
+                                                GtkAspell *gtkaspell);
 static void change_dict_cb                     (GtkWidget      *w, 
                                                 GtkAspell      *gtkaspell);
 static void switch_to_alternate_cb             (GtkWidget      *w, 
@@ -158,8 +235,8 @@ static void switch_to_alternate_cb          (GtkWidget      *w,
 /* Misc. helper functions */
 static void            set_point_continue              (GtkAspell *gtkaspell);
 static void            continue_check                  (gpointer *gtkaspell);
-static gboolean        iswordsep                       (unsigned char c);
-static guchar          get_text_index_whar             (GtkAspell *gtkaspell, 
+static gboolean        iswordsep                       (gunichar c);
+static gunichar                get_text_index_whar             (GtkAspell *gtkaspell, 
                                                         int pos);
 static gboolean        get_word_from_pos               (GtkAspell *gtkaspell, 
                                                         gint pos, 
@@ -174,7 +251,7 @@ static void                 change_color                    (GtkAspell *gtkaspell,
                                                         gint end, 
                                                         gchar *newtext,
                                                         GdkColor *color);
-static guchar*         convert_to_aspell_encoding      (const guchar *encoding);
+static gchar*          convert_to_aspell_encoding      (const gchar *encoding);
 static gint            compare_dict                    (Dictionary *a, 
                                                         Dictionary *b);
 static void            dictionary_delete               (Dictionary *dict);
@@ -185,31 +262,78 @@ 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);
 
-GtkAspellCheckers *gtkaspell_checkers_new(void)
+static void            gtkaspell_free_dictionary_list  (GSList *list);
+static GSList*         gtkaspell_get_dictionary_list   (const char *aspell_path,
+                                                gint refresh);
+
+static void            gtkaspell_uncheck_all           (GtkAspell *gtkaspell);
+
+static gint get_textview_buffer_charcount(GtkTextView *view)
+{
+       GtkTextBuffer *buffer;
+
+       g_return_val_if_fail(view, 0);
+
+       buffer = gtk_text_view_get_buffer(view);
+       g_return_val_if_fail(buffer, 0);
+
+       return gtk_text_buffer_get_char_count(buffer);
+}
+static gint get_textview_buffer_offset(GtkTextView *view)
+{
+       GtkTextBuffer * buffer;
+       GtkTextMark * mark;
+       GtkTextIter iter;
+
+       g_return_val_if_fail(view, 0);
+
+       buffer = gtk_text_view_get_buffer(view);
+       g_return_val_if_fail(buffer, 0);
+
+       mark = gtk_text_buffer_get_insert(buffer);
+       g_return_val_if_fail(mark, 0);
+
+       gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
+
+       return gtk_text_iter_get_offset(&iter);
+}
+static void set_textview_buffer_offset(GtkTextView *view, gint offset)
+{
+       GtkTextBuffer *buffer;
+       GtkTextIter iter;
+
+       g_return_if_fail(view);
+
+       buffer = gtk_text_view_get_buffer(view);
+       g_return_if_fail(buffer);
+
+       gtk_text_buffer_get_iter_at_offset(buffer, &iter, offset);
+       gtk_text_buffer_place_cursor(buffer, &iter);
+}
+/******************************************************************************/
+
+void gtkaspell_checkers_init(void)
 {
-       GtkAspellCheckers *gtkaspellcheckers;
-       
        gtkaspellcheckers                  = g_new(GtkAspellCheckers, 1);
        gtkaspellcheckers->checkers        = NULL;
        gtkaspellcheckers->dictionary_list = NULL;
        gtkaspellcheckers->error_message   = NULL;
-       
-       return gtkaspellcheckers;
 }
        
-GtkAspellCheckers *gtkaspell_checkers_delete(void)
+void gtkaspell_checkers_quit(void)
 {
        GSList *checkers;
        GSList *dict_list;
 
        if (gtkaspellcheckers == NULL) 
-               return NULL;
+               return;
 
        if ((checkers  = gtkaspellcheckers->checkers)) {
                debug_print("Aspell: number of running checkers to delete %d\n",
@@ -217,6 +341,7 @@ GtkAspellCheckers *gtkaspell_checkers_delete(void)
 
                g_slist_foreach(checkers, free_checkers, NULL);
                g_slist_free(checkers);
+               gtkaspellcheckers->checkers = NULL;
        }
 
        if ((dict_list = gtkaspellcheckers->dictionary_list)) {
@@ -228,8 +353,8 @@ GtkAspellCheckers *gtkaspell_checkers_delete(void)
        }
 
        g_free(gtkaspellcheckers->error_message);
-
-       return NULL;
+       gtkaspellcheckers->error_message = NULL;
+       return;
 }
 
 static void gtkaspell_checkers_error_message (gchar *message)
@@ -237,7 +362,8 @@ static void gtkaspell_checkers_error_message (gchar *message)
        gchar *tmp;
        if (gtkaspellcheckers->error_message) {
                tmp = g_strdup_printf("%s\n%s", 
-                                     gtkaspellcheckers->error_message, message);
+                                     gtkaspellcheckers->error_message,
+                                     message);
                g_free(message);
                g_free(gtkaspellcheckers->error_message);
                gtkaspellcheckers->error_message = tmp;
@@ -245,6 +371,12 @@ static void gtkaspell_checkers_error_message (gchar *message)
                gtkaspellcheckers->error_message = message;
 }
 
+const char *gtkaspell_checkers_strerror(void)
+{
+       g_return_val_if_fail(gtkaspellcheckers, "");
+       return gtkaspellcheckers->error_message;
+}
+
 void gtkaspell_checkers_reset_error(void)
 {
        g_return_if_fail(gtkaspellcheckers);
@@ -256,17 +388,31 @@ void gtkaspell_checkers_reset_error(void)
 
 GtkAspell *gtkaspell_new(const gchar *dictionary_path,
                         const gchar *dictionary, 
+                        const gchar *alt_dictionary, 
                         const gchar *encoding,
                         gint  misspelled_color,
                         gboolean check_while_typing,
+                        gboolean recheck_when_changing_dict,
                         gboolean use_alternate,
-                        GtkSText *gtktext)
+                        gboolean use_both_dicts,
+                        GtkTextView *gtktext,
+                        GtkWindow *parent_win,
+                        void (*spell_menu_cb)(void *data),
+                        void *data)
 {
        Dictionary      *dict;
        GtkAspell       *gtkaspell;
        GtkAspeller     *gtkaspeller;
+       GtkTextBuffer *buffer;
 
        g_return_val_if_fail(gtktext, NULL);
+       g_return_val_if_fail(dictionary && strlen(dictionary) > 0, 
+                       NULL);
+
+       g_return_val_if_fail(dictionary_path && strlen(dictionary_path) > 0, 
+                       NULL);
+
+       buffer = gtk_text_view_get_buffer(gtktext);
        
        dict           = g_new0(Dictionary, 1);
        dict->fullname = g_strdup(dictionary);
@@ -283,7 +429,26 @@ GtkAspell *gtkaspell_new(const gchar *dictionary_path,
        gtkaspell->dictionary_path    = g_strdup(dictionary_path);
 
        gtkaspell->gtkaspeller        = gtkaspeller;
-       gtkaspell->alternate_speller  = NULL;
+
+       if (use_alternate && alt_dictionary && *alt_dictionary) {
+               Dictionary      *alt_dict;
+               GtkAspeller     *alt_gtkaspeller;
+
+               alt_dict               = g_new0(Dictionary, 1);
+               alt_dict->fullname = g_strdup(alt_dictionary);
+               alt_dict->encoding = g_strdup(encoding);
+
+               alt_gtkaspeller    = gtkaspeller_new(alt_dict);
+               dictionary_delete(alt_dict);
+
+               if (!alt_gtkaspeller)
+                       return NULL;
+
+               gtkaspell->alternate_speller  = alt_gtkaspeller;
+       } else {
+               gtkaspell->alternate_speller  = NULL;
+       }
+
        gtkaspell->theword[0]         = 0x00;
        gtkaspell->start_pos          = 0;
        gtkaspell->end_pos            = 0;
@@ -291,182 +456,177 @@ GtkAspell *gtkaspell_new(const gchar *dictionary_path,
        gtkaspell->end_check_pos      = -1;
        gtkaspell->misspelled         = -1;
        gtkaspell->check_while_typing = check_while_typing;
+       gtkaspell->recheck_when_changing_dict = recheck_when_changing_dict;
        gtkaspell->continue_check     = NULL;
-       gtkaspell->config_menu        = NULL;
-       gtkaspell->popup_config_menu  = NULL;
-       gtkaspell->sug_menu           = NULL;
        gtkaspell->replace_entry      = NULL;
        gtkaspell->gtktext            = gtktext;
        gtkaspell->default_sug_mode   = ASPELL_FASTMODE;
        gtkaspell->max_sug            = -1;
        gtkaspell->suggestions_list   = NULL;
        gtkaspell->use_alternate      = use_alternate;
+       gtkaspell->use_both_dicts     = use_both_dicts;
+       gtkaspell->parent_window      = GTK_WIDGET(parent_win);
+       gtkaspell->menu_changed_cb = spell_menu_cb;
+       gtkaspell->menu_changed_data = data;
 
        allocate_color(gtkaspell, misspelled_color);
 
-       gtk_signal_connect_after(GTK_OBJECT(gtktext), "insert-text",
-                                GTK_SIGNAL_FUNC(entry_insert_cb), gtkaspell);
-       gtk_signal_connect_after(GTK_OBJECT(gtktext), "delete-text",
-                                GTK_SIGNAL_FUNC(entry_delete_cb), gtkaspell);
-       gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event",
-                          GTK_SIGNAL_FUNC(button_press_intercept_cb), gtkaspell);
+       g_signal_connect_after(G_OBJECT(buffer), "insert-text",
+                              G_CALLBACK(entry_insert_cb), gtkaspell);
+       g_signal_connect_after(G_OBJECT(buffer), "delete-range",
+                              G_CALLBACK(entry_delete_cb), gtkaspell);
+       /*g_signal_connect(G_OBJECT(gtktext), "button-press-event",
+                        G_CALLBACK(button_press_intercept_cb),
+                        gtkaspell);*/
+       g_signal_connect(G_OBJECT(gtktext), "populate-popup",
+                        G_CALLBACK(button_press_intercept_cb), gtkaspell);
        
-       debug_print("Aspell: created gtkaspell %0x\n", (guint) gtkaspell);
+       debug_print("Aspell: created gtkaspell %p\n", gtkaspell);
 
        return gtkaspell;
 }
 
-void gtkaspell_delete(GtkAspell * gtkaspell) 
+void gtkaspell_delete(GtkAspell *gtkaspell) 
 {
-       GtkSText *gtktext = gtkaspell->gtktext;
+       GtkTextView *gtktext = gtkaspell->gtktext;
        
-        gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
-                                      GTK_SIGNAL_FUNC(entry_insert_cb),
-                                     gtkaspell);
-        gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
-                                      GTK_SIGNAL_FUNC(entry_delete_cb),
-                                     gtkaspell);
-       gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
-                                      GTK_SIGNAL_FUNC(button_press_intercept_cb),
-                                     gtkaspell);
+        g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
+                                            G_CALLBACK(entry_insert_cb),
+                                            gtkaspell);
+       g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
+                                            G_CALLBACK(entry_delete_cb),
+                                            gtkaspell);
+       g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
+                                            G_CALLBACK(button_press_intercept_cb),
+                                            gtkaspell);
 
        gtkaspell_uncheck_all(gtkaspell);
        
        gtkaspeller_delete(gtkaspell->gtkaspeller);
 
-       if (gtkaspell->use_alternate && gtkaspell->alternate_speller)
+       if (gtkaspell->alternate_speller)
                gtkaspeller_delete(gtkaspell->alternate_speller);
 
-       if (gtkaspell->sug_menu)
-               gtk_widget_destroy(gtkaspell->sug_menu);
-
-       if (gtkaspell->popup_config_menu)
-               gtk_widget_destroy(gtkaspell->popup_config_menu);
-
-       if (gtkaspell->config_menu)
-               gtk_widget_destroy(gtkaspell->config_menu);
-
        if (gtkaspell->suggestions_list)
                free_suggestions_list(gtkaspell);
 
        g_free((gchar *)gtkaspell->dictionary_path);
+       gtkaspell->dictionary_path = NULL;
 
-       debug_print("Aspell: deleting gtkaspell %0x\n", (guint) gtkaspell);
+       debug_print("Aspell: deleting gtkaspell %p\n", gtkaspell);
 
        g_free(gtkaspell);
 
        gtkaspell = NULL;
 }
 
-static void entry_insert_cb(GtkSText *gtktext,
-                           gchar *newtext, 
-                           guint len,
-                           guint *ppos, 
-                            GtkAspell *gtkaspell) 
+static void entry_insert_cb(GtkTextBuffer *textbuf,
+                           GtkTextIter *iter,
+                           gchar *newtext,
+                           gint len,
+                           GtkAspell *gtkaspell)
 {
+       guint pos;
+
        g_return_if_fail(gtkaspell->gtkaspeller->checker);
 
        if (!gtkaspell->check_while_typing)
                return;
-       
-       /* We must insert ourselves the character so the
-        * color of the inserted character is the default color.
-        * Never mess with set_insertion when frozen.
-        */
 
-       gtk_stext_freeze(gtktext);
-       gtk_stext_backward_delete(GTK_STEXT(gtktext), len);
-       gtk_stext_insert(GTK_STEXT(gtktext), NULL, NULL, NULL, newtext, len);
-       *ppos = gtk_stext_get_point(GTK_STEXT(gtktext));
-              
-       if (iswordsep(newtext[0])) {
+       pos = gtk_text_iter_get_offset(iter);
+       
+       if (iswordsep(g_utf8_get_char(newtext))) {
                /* did we just end a word? */
-               if (*ppos >= 2) 
-                       check_at(gtkaspell, *ppos - 2);
+               if (pos >= 2)
+                       check_at(gtkaspell, pos - 2);
 
                /* did we just split a word? */
-               if (*ppos < gtk_stext_get_length(gtktext))
-                       check_at(gtkaspell, *ppos + 1);
+               if (pos < gtk_text_buffer_get_char_count(textbuf))
+                       check_at(gtkaspell, pos + 1);
        } else {
                /* check as they type, *except* if they're typing at the end (the most
                  * common case).
                  */
-               if (*ppos < gtk_stext_get_length(gtktext) &&
-                   !iswordsep(get_text_index_whar(gtkaspell, *ppos))) {
-                       check_at(gtkaspell, *ppos - 1);
+               if (pos < gtk_text_buffer_get_char_count(textbuf) &&
+                   !iswordsep(get_text_index_whar(gtkaspell, pos))) {
+                       check_at(gtkaspell, pos - 1);
                }
        }
-
-       gtk_stext_thaw(gtktext);
-       gtk_editable_set_position(GTK_EDITABLE(gtktext), *ppos);
 }
 
-static void entry_delete_cb(GtkSText *gtktext,
-                           gint start, 
-                           gint end, 
-                           GtkAspell *gtkaspell) 
+static void entry_delete_cb(GtkTextBuffer *textbuf,
+                           GtkTextIter *startiter,
+                           GtkTextIter *enditer,
+                           GtkAspell *gtkaspell)
 {
        int origpos;
+       gint start, end;
     
        g_return_if_fail(gtkaspell->gtkaspeller->checker);
 
        if (!gtkaspell->check_while_typing)
                return;
 
-       origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
+       start = gtk_text_iter_get_offset(startiter);
+       end = gtk_text_iter_get_offset(enditer);
+       origpos = get_textview_buffer_offset(gtkaspell->gtktext);
        if (start) {
                check_at(gtkaspell, start - 1);
                check_at(gtkaspell, start);
        }
 
-       gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
-       gtk_stext_set_point(gtktext, origpos);
+       set_textview_buffer_offset(gtkaspell->gtktext, origpos);
        /* this is to *UNDO* the selection, in case they were holding shift
          * while hitting backspace. */
-       gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);
+       /* needed with textview ??? */
+       /* gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos); */
 }
 
-/* ok, this is pretty wacky:
- * we need to let the right-mouse-click go through, so it moves the cursor,
- * but we *can't* let it go through, because GtkText interprets rightclicks as
- * weird selection modifiers.
- *
- * so what do we do?  forge rightclicks as leftclicks, then popup the menu.
- * HACK HACK HACK.
- */
-static gint button_press_intercept_cb(GtkSText *gtktext, GdkEvent *e, GtkAspell *gtkaspell) 
+static void button_press_intercept_cb(GtkTextView *gtktext,
+                       GtkMenu *menu, GtkAspell *gtkaspell)
 {
-       GdkEventButton *eb;
-       gboolean retval;
+       GtkMenuItem *menuitem;
+       GSList *spell_menu = NULL;
+       GSList *items;
+       gboolean suggest = FALSE;
 
-       g_return_val_if_fail(gtkaspell->gtkaspeller->checker, FALSE);
+       menuitem = GTK_MENU_ITEM(gtk_separator_menu_item_new());
+       gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
+       gtk_widget_show(GTK_WIDGET(menuitem));
 
-       if (e->type != GDK_BUTTON_PRESS) 
-               return FALSE;
-       eb = (GdkEventButton*) e;
+       gtktext = gtkaspell->gtktext;
 
-       if (eb->button != 3) 
-               return FALSE;
+       gtkaspell->orig_pos = get_textview_buffer_offset(gtktext);
 
-       /* forge the leftclick */
-       eb->button = 1;
+       if (check_at(gtkaspell, gtkaspell->orig_pos)) {
+
+               if (misspelled_suggest(gtkaspell, gtkaspell->theword)) {
+                       spell_menu = make_sug_menu(gtkaspell);
+                       suggest = TRUE;
+               }
+       } 
+       if (!spell_menu) 
+               spell_menu = gtkaspell_make_config_menu(gtkaspell);
+       
+       spell_menu = g_slist_reverse(spell_menu);
+       for (items = spell_menu;
+            items; items = items->next) {
+               menuitem = GTK_MENU_ITEM(items->data);
+               gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
+               gtk_widget_show(GTK_WIDGET(menuitem));
+       }
+       g_slist_free(spell_menu);
+       
+       g_signal_connect(G_OBJECT(menu), "deactivate",
+                                G_CALLBACK(destroy_menu), 
+                                gtkaspell);
+       if (suggest)
+               g_signal_connect(G_OBJECT(menu),
+                       "key_press_event",
+                       G_CALLBACK(aspell_key_pressed), gtkaspell);
 
-        gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
-                                        GTK_SIGNAL_FUNC(button_press_intercept_cb), 
-                                        gtkaspell);
-       gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "button-press-event",
-                               e, &retval);
-       gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
-                                          GTK_SIGNAL_FUNC(button_press_intercept_cb), 
-                                          gtkaspell);
-       gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "button-press-event");
-    
-       /* now do the menu wackiness */
-       popup_menu(gtkaspell, eb);
-       gtk_grab_remove(GTK_WIDGET(gtktext));
-       return TRUE;
-}
 
+}
 /* Checker creation */
 static GtkAspeller *gtkaspeller_new(Dictionary *dictionary)
 {
@@ -480,7 +640,8 @@ static GtkAspeller *gtkaspeller_new(Dictionary *dictionary)
        g_return_val_if_fail(dictionary, NULL);
 
        if (dictionary->fullname == NULL)
-               gtkaspell_checkers_error_message(g_strdup(_("No dictionary selected.")));
+               gtkaspell_checkers_error_message(
+                               g_strdup(_("No dictionary selected.")));
        
        g_return_val_if_fail(dictionary->fullname, NULL);
        
@@ -510,8 +671,8 @@ static GtkAspeller *gtkaspeller_new(Dictionary *dictionary)
                                gtkaspellcheckers->checkers,
                                gtkaspeller);
 
-               debug_print("Aspell: Created a new gtkaspeller %0x\n",
-                               (gint) gtkaspeller);
+               debug_print("Aspell: Created a new gtkaspeller %p\n",
+                               gtkaspeller);
        } else {
                dictionary_delete(dict);
 
@@ -547,7 +708,8 @@ static GtkAspeller *gtkaspeller_real_new(Dictionary *dict)
        delete_aspell_config(config);
 
        if (aspell_error_number(ret) != 0) {
-               gtkaspellcheckers->error_message = g_strdup(aspell_error_message(ret));
+               gtkaspellcheckers->error_message
+                       = g_strdup(aspell_error_message(ret));
                
                delete_aspell_can_have_error(ret);
                
@@ -568,8 +730,8 @@ static GtkAspeller *gtkaspeller_delete(GtkAspeller *gtkaspeller)
                g_slist_remove(gtkaspellcheckers->checkers, 
                                gtkaspeller);
 
-       debug_print("Aspell: Deleting gtkaspeller %0x.\n", 
-                       (gint) gtkaspeller);
+       debug_print("Aspell: Deleting gtkaspeller %p.\n", 
+                       gtkaspeller);
 
        gtkaspeller_real_delete(gtkaspeller);
 
@@ -590,8 +752,8 @@ static GtkAspeller *gtkaspeller_real_delete(GtkAspeller *gtkaspeller)
 
        dictionary_delete(gtkaspeller->dictionary);
 
-       debug_print("Aspell: gtkaspeller %0x deleted.\n", 
-                   (gint) gtkaspeller);
+       debug_print("Aspell: gtkaspeller %p deleted.\n", 
+                   gtkaspeller);
 
        g_free(gtkaspeller);
 
@@ -634,7 +796,8 @@ static gboolean set_dictionary(AspellConfig *config, Dictionary *dict)
                jargon = NULL;
 
        debug_print("Aspell: language: %s, jargon: %s, size: %s\n",
-                   language, jargon, size);
+                   language, jargon ? jargon : "",
+                    size ? size : "");
        
        if (language)
                CONFIG_REPLACE_RETURN_FALSE_IF_FAIL("lang", language);
@@ -646,7 +809,8 @@ static gboolean set_dictionary(AspellConfig *config, Dictionary *dict)
                gchar *aspell_enc;
        
                aspell_enc = convert_to_aspell_encoding (dict->encoding);
-               aspell_config_replace(config, "encoding", (const char *) aspell_enc);
+               aspell_config_replace(config, "encoding",
+                                     (const char *) aspell_enc);
                g_free(aspell_enc);
 
                RETURN_FALSE_IF_CONFIG_ERROR();
@@ -655,40 +819,31 @@ static gboolean set_dictionary(AspellConfig *config, Dictionary *dict)
        return TRUE;
 }
 
-guchar *gtkaspell_get_dict(GtkAspell *gtkaspell)
-{
-
-       g_return_val_if_fail(gtkaspell->gtkaspeller->config,     NULL);
-       g_return_val_if_fail(gtkaspell->gtkaspeller->dictionary, NULL);
-       
-       return g_strdup(gtkaspell->gtkaspeller->dictionary->dictname);
-}
-  
-guchar *gtkaspell_get_path(GtkAspell *gtkaspell)
-{
-       guchar *path;
-       Dictionary *dict;
-
-       g_return_val_if_fail(gtkaspell->gtkaspeller->config, NULL);
-       g_return_val_if_fail(gtkaspell->gtkaspeller->dictionary, NULL);
-
-       dict = gtkaspell->gtkaspeller->dictionary;
-       path = g_strndup(dict->fullname, dict->dictname - dict->fullname);
-
-       return path;
-}
-
 /* set_sug_mode_cb() - Menu callback: Set the suggestion mode */
 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->menu_changed_cb)
+               gtkaspell->menu_changed_cb(gtkaspell->menu_changed_data);
+}
 
-       if (gtkaspell->config_menu)
-               populate_submenu(gtkaspell, gtkaspell->config_menu);
+/* set_sug_mode_cb() - Menu callback: Set the suggestion mode */
+static void set_use_both_cb(GtkMenuItem *w, GtkAspell *gtkaspell)
+{
+       gtkaspell->use_both_dicts = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w));
+
+       if (gtkaspell->recheck_when_changing_dict) {
+               gtkaspell_highlight_all(gtkaspell);
+       }
+
+       if (gtkaspell->menu_changed_cb)
+               gtkaspell->menu_changed_cb(gtkaspell->menu_changed_data);
 }
 
 static void set_real_sug_mode(GtkAspell *gtkaspell, const char *themode)
@@ -722,8 +877,8 @@ gboolean gtkaspell_set_sug_mode(GtkAspell *gtkaspell, gint themode)
        g_return_val_if_fail(gtkaspell->gtkaspeller, FALSE);
        g_return_val_if_fail(gtkaspell->gtkaspeller->config, FALSE);
 
-       debug_print("Aspell: setting sug mode of gtkaspeller %0x to %d\n",
-                       (guint) gtkaspell->gtkaspeller, themode);
+       debug_print("Aspell: setting sug mode of gtkaspeller %p to %d\n",
+                       gtkaspell->gtkaspeller, themode);
 
        config = gtkaspell->gtkaspeller->config;
 
@@ -751,7 +906,7 @@ gboolean gtkaspell_set_sug_mode(GtkAspell *gtkaspell, gint themode)
 }
 
 /* misspelled_suggest() - Create a suggestion list for  word  */
-static GList *misspelled_suggest(GtkAspell *gtkaspell, guchar *word) 
+static GList *misspelled_suggest(GtkAspell *gtkaspell, gchar *word) 
 {
        const guchar          *newword;
        GList                 *list = NULL;
@@ -763,13 +918,14 @@ static GList *misspelled_suggest(GtkAspell *gtkaspell, guchar *word)
        if (!aspell_speller_check(gtkaspell->gtkaspeller->checker, word, -1)) {
                free_suggestions_list(gtkaspell);
 
-               suggestions = aspell_speller_suggest(gtkaspell->gtkaspeller->checker, 
+               suggestions = aspell_speller_suggest(
+                               gtkaspell->gtkaspeller->checker,
                                                     (const char *)word, -1);
                elements    = aspell_word_list_elements(suggestions);
                list        = g_list_append(list, g_strdup(word)); 
                
-               while ((newword = aspell_string_enumeration_next(elements)) != NULL)
-                       list = g_list_append(list, g_strdup(newword));
+               while ((newword = (guchar *)aspell_string_enumeration_next(elements)) != NULL)
+                       list = g_list_append(list, g_strdup((gchar *)newword));
 
                gtkaspell->max_sug          = g_list_length(list) - 1;
                gtkaspell->suggestions_list = list;
@@ -785,28 +941,46 @@ static GList *misspelled_suggest(GtkAspell *gtkaspell, guchar *word)
 /* misspelled_test() - Just test if word is correctly spelled */  
 static int misspelled_test(GtkAspell *gtkaspell, unsigned char *word) 
 {
-       return aspell_speller_check(gtkaspell->gtkaspeller->checker, word, -1) ? 0 : 1; 
+       gint result = aspell_speller_check(gtkaspell->gtkaspeller->checker, (char *)word, -1)
+                                   ? 0 : 1;
+       if (result && gtkaspell->use_both_dicts && gtkaspell->alternate_speller) {
+               use_alternate_dict(gtkaspell);
+               result = aspell_speller_check(gtkaspell->gtkaspeller->checker, (char *)word, -1)
+                                   ? 0 : 1;
+               use_alternate_dict(gtkaspell);
+       }
+       return result;
 }
 
 
-static gboolean iswordsep(unsigned char c) 
+static gboolean iswordsep(gunichar c) 
 {
-       return !isalpha(c) && c != '\'';
+       return (g_unichar_isspace(c) || g_unichar_ispunct(c)) && c != (gunichar)'\'';
 }
 
-static guchar get_text_index_whar(GtkAspell *gtkaspell, int pos) 
+static gunichar get_text_index_whar(GtkAspell *gtkaspell, int pos) 
 {
-       guchar a;
-       gchar *text;
-       
-       text = gtk_editable_get_chars(GTK_EDITABLE(gtkaspell->gtktext), pos, 
-                                     pos + 1);
-       if (text == NULL) 
-               return 0;
+       GtkTextView *view = gtkaspell->gtktext;
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer(view);
+       GtkTextIter start, end;
+       gchar *utf8chars;
+       gunichar a = '\0';
 
-       a = (guchar) *text;
+       gtk_text_buffer_get_iter_at_offset(buffer, &start, pos);
+       gtk_text_buffer_get_iter_at_offset(buffer, &end, pos+1);
 
-       g_free(text);
+       utf8chars = gtk_text_iter_get_text(&start, &end);
+       if (is_ascii_str(utf8chars)) {
+               a = utf8chars ? (gunichar)utf8chars[0] : '\0' ;
+       } else {
+               gchar *tr = conv_iconv_strdup(utf8chars, CS_UTF_8, 
+                               gtkaspell->gtkaspeller->dictionary->encoding);
+               if (tr) {
+                       a = g_utf8_get_char(tr);
+                       g_free(tr);
+               }
+       }
+       g_free(utf8chars);
 
        return a;
 }
@@ -826,8 +1000,8 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
        gint start;
        gint end;
                  
-       guchar c;
-       GtkSText *gtktext;
+       gunichar c;
+       GtkTextView *gtktext;
        
        gtktext = gtkaspell->gtktext;
        if (iswordsep(get_text_index_whar(gtkaspell, pos))) 
@@ -840,9 +1014,13 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
         
        for (start = pos; start >= 0; --start) {
                c = get_text_index_whar(gtkaspell, start);
-               if (c == '\'') {
+               if (c == (gunichar)'\'') {
                        if (start > 0) {
-                               if (!isalpha(get_text_index_whar(gtkaspell,
+                               if (g_unichar_isspace(get_text_index_whar(gtkaspell,
+                                                                start - 1))
+                               ||  g_unichar_ispunct(get_text_index_whar(gtkaspell,
+                                                                start - 1))
+                               ||  g_unichar_isdigit(get_text_index_whar(gtkaspell,
                                                                 start - 1))) {
                                        /* start_quote = TRUE; */
                                        break;
@@ -853,17 +1031,21 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
                                break;
                        }
                }
-               else if (!isalpha(c))
+               else if (g_unichar_isspace(c) || g_unichar_ispunct(c) || g_unichar_isdigit(c))
                                break;
        }
 
        start++;
 
-       for (end = pos; end < gtk_stext_get_length(gtktext); end++) {
+       for (end = pos; end < get_textview_buffer_charcount(gtktext); end++) {
                c = get_text_index_whar(gtkaspell, end); 
-               if (c == '\'') {
-                       if (end < gtk_stext_get_length(gtktext)) {
-                               if (!isalpha(get_text_index_whar(gtkaspell,
+               if (c == (gunichar)'\'') {
+                       if (end < get_textview_buffer_charcount(gtktext)) {
+                               if (g_unichar_isspace(get_text_index_whar(gtkaspell,
+                                                                end + 1))
+                               ||  g_unichar_ispunct(get_text_index_whar(gtkaspell,
+                                                                end + 1))
+                               ||  g_unichar_isdigit(get_text_index_whar(gtkaspell,
                                                                 end + 1))) {
                                        /* end_quote = TRUE; */
                                        break;
@@ -874,7 +1056,7 @@ static gboolean get_word_from_pos(GtkAspell *gtkaspell, gint pos,
                                break;
                        }
                }
-               else if(!isalpha(c))
+               else if (g_unichar_isspace(c) || g_unichar_ispunct(c) || g_unichar_isdigit(c))
                                break;
        }
                                                
@@ -885,10 +1067,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((char *)buf, conv, buflen-1);
+                       buf[buflen-1]='\0';
+                       g_free(conv);
                } else
                        return FALSE;
        }
@@ -900,7 +1090,7 @@ static gboolean check_at(GtkAspell *gtkaspell, gint from_pos)
 {
        gint          start, end;
        unsigned char buf[GTKASPELLWORDSIZE];
-       GtkSText     *gtktext;
+       GtkTextView     *gtktext;
 
        g_return_val_if_fail(from_pos >= 0, FALSE);
     
@@ -910,17 +1100,18 @@ static gboolean check_at(GtkAspell *gtkaspell, gint from_pos)
                               &start, &end))
                return FALSE;
 
-       if (misspelled_test(gtkaspell, buf)) {
-               strncpy(gtkaspell->theword, buf, GTKASPELLWORDSIZE - 1);
+       if (misspelled_test(gtkaspell, buf)
+       && strcasecmp((char *)buf, "sylpheed") && strcasecmp((char *)buf, "claws-mail")) {
+               strncpy(gtkaspell->theword, (gchar *)buf, GTKASPELLWORDSIZE - 1);
                gtkaspell->theword[GTKASPELLWORDSIZE - 1] = 0;
                gtkaspell->start_pos  = start;
                gtkaspell->end_pos    = end;
                free_suggestions_list(gtkaspell);
 
-               change_color(gtkaspell, start, end, buf, &(gtkaspell->highlight));
+               change_color(gtkaspell, start, end, (gchar *)buf, &(gtkaspell->highlight));
                return TRUE;
        } else {
-               change_color(gtkaspell, start, end, buf, NULL);
+               change_color(gtkaspell, start, end, (gchar *)buf, NULL);
                return FALSE;
        }
 }
@@ -942,10 +1133,10 @@ static gboolean check_next_prev(GtkAspell *gtkaspell, gboolean forward)
                maxpos--;
        } 
 
-       pos = gtk_editable_get_position(GTK_EDITABLE(gtkaspell->gtktext));
+       pos = get_textview_buffer_offset(gtkaspell->gtktext);
        gtkaspell->orig_pos = pos;
        while (iswordsep(get_text_index_whar(gtkaspell, pos)) &&
-              pos > minpos && pos <= maxpos) 
+              pos > minpos && pos <= maxpos)
                pos += direc;
        while (!(misspelled = check_at(gtkaspell, pos)) &&
               pos > minpos && pos <= maxpos) {
@@ -954,33 +1145,52 @@ static gboolean check_next_prev(GtkAspell *gtkaspell, gboolean forward)
                       pos > minpos && pos <= maxpos)
                        pos += direc;
 
-               while (iswordsep(get_text_index_whar(gtkaspell, pos)) && 
-                      pos > minpos && pos <= maxpos) 
+               while (iswordsep(get_text_index_whar(gtkaspell, pos)) &&
+                      pos > minpos && pos <= maxpos)
                        pos += direc;
        }
        if (misspelled) {
+               GSList *list, *cur;
+               GtkWidget *menu;
                misspelled_suggest(gtkaspell, gtkaspell->theword);
 
                if (forward)
                        gtkaspell->orig_pos = gtkaspell->end_pos;
 
-               gtk_stext_set_point(GTK_STEXT(gtkaspell->gtktext),
-                               gtkaspell->end_pos);
-               gtk_editable_set_position(GTK_EDITABLE(gtkaspell->gtktext),
+               set_textview_buffer_offset(gtkaspell->gtktext,
                                gtkaspell->end_pos);
-               gtk_menu_popup(make_sug_menu(gtkaspell), NULL, NULL, 
+               /* scroll line to window center */
+               gtk_text_view_scroll_to_mark(gtkaspell->gtktext,
+                       gtk_text_buffer_get_insert(
+                               gtk_text_view_get_buffer(gtkaspell->gtktext)),
+                       0.0, TRUE, 0.0, 0.5);
+               /* let textview recalculate coordinates (set_menu_pos) */
+               while (gtk_events_pending ())
+                       gtk_main_iteration ();
+
+               list = make_sug_menu(gtkaspell);
+               menu = gtk_menu_new();
+               for (cur = list; cur; cur = cur->next)
+                       gtk_menu_append(menu, GTK_WIDGET(cur->data));
+               g_slist_free(list);
+               gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
                                set_menu_pos, gtkaspell, 0, GDK_CURRENT_TIME);
+               g_signal_connect(G_OBJECT(menu), "deactivate",
+                                        G_CALLBACK(destroy_menu), 
+                                        gtkaspell);
+               g_signal_connect(G_OBJECT(menu),
+                       "key_press_event",
+                       G_CALLBACK(aspell_key_pressed), gtkaspell);
+
+
        } else {
                reset_theword_data(gtkaspell);
 
-               gtkaspell_alert_dialog(_("No misspelled word found."));
-               gtk_stext_set_point(GTK_STEXT(gtkaspell->gtktext),
-                                   gtkaspell->orig_pos);
-               gtk_editable_set_position(GTK_EDITABLE(gtkaspell->gtktext),
+               alertpanel_notice(_("No misspelled word found."));
+               set_textview_buffer_offset(gtkaspell->gtktext,
                                          gtkaspell->orig_pos);
-
-               
        }
+
        return misspelled;
 }
 
@@ -988,7 +1198,7 @@ void gtkaspell_check_backwards(GtkAspell *gtkaspell)
 {
        gtkaspell->continue_check = NULL;
        gtkaspell->end_check_pos =
-               gtk_stext_get_length(GTK_STEXT(gtkaspell->gtktext));
+               get_textview_buffer_charcount(gtkaspell->gtktext);
        check_next_prev(gtkaspell, FALSE);
 }
 
@@ -996,57 +1206,54 @@ void gtkaspell_check_forwards_go(GtkAspell *gtkaspell)
 {
 
        gtkaspell->continue_check = NULL;
-       gtkaspell->end_check_pos
-               = gtk_stext_get_length(GTK_STEXT(gtkaspell->gtktext));
+       gtkaspell->end_check_pos =
+               get_textview_buffer_charcount(gtkaspell->gtktext);
        check_next_prev(gtkaspell, TRUE);
 }
 
 void gtkaspell_check_all(GtkAspell *gtkaspell)
 {      
-       GtkWidget *gtktext;
+       GtkTextView *gtktext;
        gint start, end;
+       GtkTextBuffer *buffer;
+       GtkTextIter startiter, enditer;
 
        g_return_if_fail(gtkaspell);
        g_return_if_fail(gtkaspell->gtktext);
 
-       gtktext = (GtkWidget *) gtkaspell->gtktext;
-
-       start = 0;      
-       end   = gtk_stext_get_length(GTK_STEXT(gtktext));
-
-       if (GTK_EDITABLE(gtktext)->has_selection) {
-               start = GTK_EDITABLE(gtktext)->selection_start_pos;
-               end   = GTK_EDITABLE(gtktext)->selection_end_pos;
-       }
-
-       if (start > end) {
+       gtktext = gtkaspell->gtktext;
+       buffer = gtk_text_view_get_buffer(gtktext);
+       gtk_text_buffer_get_selection_bounds(buffer, &startiter, &enditer);
+       start = gtk_text_iter_get_offset(&startiter);
+       end = gtk_text_iter_get_offset(&enditer);
+
+       if (start == end) {
+               start = 0;
+               end = gtk_text_buffer_get_char_count(buffer);
+       } else 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);
+
+       set_textview_buffer_offset(gtktext, start);
 
        gtkaspell->continue_check = continue_check;
        gtkaspell->end_check_pos  = end;
 
        gtkaspell->misspelled = check_next_prev(gtkaspell, TRUE);
-
 }      
 
 static void continue_check(gpointer *data)
 {
        GtkAspell *gtkaspell = (GtkAspell *) data;
-       gint pos = gtk_editable_get_position(GTK_EDITABLE(gtkaspell->gtktext));
+       gint pos = get_textview_buffer_offset(gtkaspell->gtktext);
        if (pos < gtkaspell->end_check_pos && gtkaspell->misspelled)
                gtkaspell->misspelled = check_next_prev(gtkaspell, TRUE);
        else
                gtkaspell->continue_check = NULL;
-               
 }
 
 void gtkaspell_highlight_all(GtkAspell *gtkaspell) 
@@ -1054,21 +1261,18 @@ void gtkaspell_highlight_all(GtkAspell *gtkaspell)
        guint     origpos;
        guint     pos = 0;
        guint     len;
-       GtkSText *gtktext;
-       gfloat    adj_value;
+       GtkTextView *gtktext;
 
        g_return_if_fail(gtkaspell->gtkaspeller->checker);      
 
        gtktext = gtkaspell->gtktext;
 
-       adj_value = gtktext->vadj->value;
-
-       len = gtk_stext_get_length(gtktext);
+       len = get_textview_buffer_charcount(gtktext);
 
-       origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
+       origpos = get_textview_buffer_offset(gtktext);
 
        while (pos < len) {
-               while (pos < len && 
+               while (pos < len &&
                       iswordsep(get_text_index_whar(gtkaspell, pos)))
                        pos++;
                while (pos < len &&
@@ -1077,33 +1281,36 @@ void gtkaspell_highlight_all(GtkAspell *gtkaspell)
                if (pos > 0)
                        check_at(gtkaspell, pos - 1);
        }
-       gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
-       gtk_stext_set_point(GTK_STEXT(gtktext), origpos);
-       gtk_adjustment_set_value(gtktext->vadj, adj_value);
+       set_textview_buffer_offset(gtktext, origpos);
 }
 
 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),
+
+       newword = (unsigned char *)gtk_editable_get_chars(GTK_EDITABLE(gtkaspell->replace_entry),
                                         0, -1);
-       
-       if (strcmp(newword, gtkaspell->theword)) {
-               replace_real_word(gtkaspell, newword);
-
-               if ((e->type == GDK_KEY_PRESS && 
-                   ((GdkEventKey *) e)->state & GDK_MOD1_MASK)) {
-                       aspell_speller_store_replacement(gtkaspell->gtkaspeller->checker, 
-                                                        gtkaspell->theword, -1, 
-                                                        newword, -1);
+
+       if (strcmp((char *)newword, gtkaspell->theword)) {
+               replace_real_word(gtkaspell, (char *)newword);
+
+               if ((e->type == GDK_KEY_PRESS &&
+                   ((GdkEventKey *) e)->state & GDK_CONTROL_MASK)) {
+                       aspell_speller_store_replacement(
+                                       gtkaspell->gtkaspeller->checker,
+                                        gtkaspell->theword, -1,
+                                        (char *)newword, -1);
                }
                gtkaspell->replace_entry = NULL;
        }
 
        g_free(newword);
 
+       if (w && GTK_IS_DIALOG(w)) {
+               gtk_widget_destroy(w);
+       }
+
        set_point_continue(gtkaspell);
 }
 
@@ -1114,22 +1321,25 @@ 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 = (unsigned char *)g_strdup((char *)newword);
 
-       replace_real_word(gtkaspell, newword);
+       replace_real_word(gtkaspell, (char *)newword);
 
        if ((e->type == GDK_KEY_PRESS && 
-           ((GdkEventKey *) e)->state & GDK_MOD1_MASK) ||
+           ((GdkEventKey *) e)->state & GDK_CONTROL_MASK) ||
            (e->type == GDK_BUTTON_RELEASE && 
-            ((GdkEventButton *) e)->state & GDK_MOD1_MASK)) {
-               aspell_speller_store_replacement(gtkaspell->gtkaspeller->checker, 
+            ((GdkEventButton *) e)->state & GDK_CONTROL_MASK)) {
+               aspell_speller_store_replacement(
+                               gtkaspell->gtkaspeller->checker,
                                                 gtkaspell->theword, -1, 
-                                                newword, -1);
+                                               (char *)newword, -1);
        }
 
        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)
@@ -1137,14 +1347,15 @@ static void replace_real_word(GtkAspell *gtkaspell, gchar *newword)
        int             oldlen, newlen, wordlen;
        gint            origpos;
        gint            pos;
-       gint            start = gtkaspell->start_pos;
-       GtkSText       *gtktext;
+       GtkTextView     *gtktext;
+       GtkTextBuffer   *textbuf;
+       GtkTextIter     startiter, enditer;
     
        if (!newword) return;
 
        gtktext = gtkaspell->gtktext;
+       textbuf = gtk_text_view_get_buffer(gtktext);
 
-       gtk_stext_freeze(GTK_STEXT(gtktext));
        origpos = gtkaspell->orig_pos;
        pos     = origpos;
        oldlen  = gtkaspell->end_pos - gtkaspell->start_pos;
@@ -1152,33 +1363,37 @@ static void replace_real_word(GtkAspell *gtkaspell, gchar *newword)
 
        newlen = strlen(newword); /* FIXME: multybyte characters? */
 
-       gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
-                                        GTK_SIGNAL_FUNC(entry_insert_cb), 
+       g_signal_handlers_block_by_func(G_OBJECT(gtktext),
+                                        G_CALLBACK(entry_insert_cb),
                                         gtkaspell);
-       gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
-                                        GTK_SIGNAL_FUNC(entry_delete_cb), 
+       g_signal_handlers_block_by_func(G_OBJECT(gtktext),
+                                        G_CALLBACK(entry_delete_cb),
                                         gtkaspell);
 
-       gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "delete-text", 
-                               gtkaspell->start_pos, gtkaspell->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), 
+       gtk_text_buffer_get_iter_at_offset(textbuf, &startiter,
+                                          gtkaspell->start_pos);
+       gtk_text_buffer_get_iter_at_offset(textbuf, &enditer,
+                                          gtkaspell->end_pos);
+       g_signal_emit_by_name(G_OBJECT(textbuf), "delete-range",
+                             &startiter, &enditer, gtkaspell);
+       g_signal_emit_by_name(G_OBJECT(textbuf), "insert-text",
+                             &startiter, newword, newlen, gtkaspell);
+
+       g_signal_handlers_unblock_by_func(G_OBJECT(gtktext),
+                                          G_CALLBACK(entry_insert_cb),
                                           gtkaspell);
-       gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
-                                          GTK_SIGNAL_FUNC(entry_delete_cb), 
+       g_signal_handlers_unblock_by_func(G_OBJECT(gtktext),
+                                          G_CALLBACK(entry_delete_cb),
                                           gtkaspell);
-       
+
        /* 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
         * to let it update correctly the word insertion and then the
         * 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 - gtkaspell->start_pos < oldlen && 
+
+       if (origpos - gtkaspell->start_pos < oldlen &&
            origpos - gtkaspell->start_pos >= 0) {
                /* Original point was in the word.
                 * Let it there unless point is going to be outside of the word
@@ -1191,44 +1406,32 @@ static void replace_real_word(GtkAspell *gtkaspell, gchar *newword)
                /* move the position according to the change of length */
                pos = origpos + newlen - oldlen;
        }
-       
-       gtkaspell->end_pos = gtkaspell->start_pos + strlen(newword); /* FIXME: multibyte characters? */
-       
-       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));
+       gtkaspell->end_pos = gtkaspell->start_pos + strlen(newword); /* FIXME: multibyte characters? */
 
+       if (get_textview_buffer_charcount(gtktext) < pos)
+               pos = get_textview_buffer_charcount(gtktext);
        gtkaspell->orig_pos = pos;
 
-       gtk_editable_set_position(GTK_EDITABLE(gtktext), gtkaspell->orig_pos);
-       gtk_stext_set_point(GTK_STEXT(gtktext), 
-                           gtk_editable_get_position(GTK_EDITABLE(gtktext)));
-
-       gtk_stext_thaw(GTK_STEXT(gtktext));
+       set_textview_buffer_offset(gtktext, gtkaspell->orig_pos);
 }
 
 /* Accept this word for this session */
 static void add_word_to_session_cb(GtkWidget *w, gpointer data)
 {
        guint     pos;
-       GtkSText *gtktext;
+       GtkTextView *gtktext;
        GtkAspell *gtkaspell = (GtkAspell *) data; 
        gtktext = gtkaspell->gtktext;
 
-       gtk_stext_freeze(GTK_STEXT(gtktext));
+       pos = get_textview_buffer_offset(gtktext);
 
-       pos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
-    
        aspell_speller_add_to_session(gtkaspell->gtkaspeller->checker,
-                                     gtkaspell->theword, 
+                                     gtkaspell->theword,
                                      strlen(gtkaspell->theword));
 
        check_at(gtkaspell, gtkaspell->start_pos);
 
-       gtk_stext_thaw(gtkaspell->gtktext);
-
        gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
 
        set_point_continue(gtkaspell);
@@ -1238,17 +1441,12 @@ 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; 
-       GtkSText *gtktext    = gtkaspell->gtktext;
 
-       gtk_stext_freeze(GTK_STEXT(gtktext));
-    
        aspell_speller_add_to_personal(gtkaspell->gtkaspeller->checker,
                                       gtkaspell->theword,
                                       strlen(gtkaspell->theword));
-    
-       check_at(gtkaspell, gtkaspell->start_pos);
 
-       gtk_stext_thaw(gtkaspell->gtktext);
+       check_at(gtkaspell, gtkaspell->start_pos);
 
        gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
        set_point_continue(gtkaspell);
@@ -1269,17 +1467,27 @@ static void check_with_alternate_cb(GtkWidget *w, gpointer data)
                gtkaspell->misspelled = misspelled;
 
                if (gtkaspell->misspelled) {
-
+                       GtkWidget *menu;
+                       GSList *list, *cur;
                        misspelled_suggest(gtkaspell, gtkaspell->theword);
 
-                       gtk_stext_set_point(GTK_STEXT(gtkaspell->gtktext),
+                       set_textview_buffer_offset(gtkaspell->gtktext,
                                            gtkaspell->end_pos);
-                       gtk_editable_set_position(GTK_EDITABLE(gtkaspell->gtktext),
-                                                 gtkaspell->end_pos);
 
-                       gtk_menu_popup(make_sug_menu(gtkaspell), NULL, NULL, 
-                                      set_menu_pos, gtkaspell, 0, 
+                       list = make_sug_menu(gtkaspell);
+                       menu = gtk_menu_new();
+                       for (cur = list; cur; cur = cur->next)
+                               gtk_menu_append(menu, GTK_WIDGET(cur->data));
+                       g_slist_free(list);
+                       gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
+                                      set_menu_pos, gtkaspell, 0,
                                       GDK_CURRENT_TIME);
+                       g_signal_connect(G_OBJECT(menu), "deactivate",
+                                        G_CALLBACK(destroy_menu), 
+                                        gtkaspell);
+                       g_signal_connect(G_OBJECT(menu),
+                               "key_press_event",
+                               G_CALLBACK(aspell_key_pressed), gtkaspell);
                        return;
                }
        } else
@@ -1288,14 +1496,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;
@@ -1306,63 +1533,95 @@ static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
 
        dialog = gtk_dialog_new();
 
-       gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
+       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);
 
-       gtk_signal_connect_object(GTK_OBJECT(dialog), "destroy",
-                                 GTK_SIGNAL_FUNC(gtk_widget_destroy), 
-                                 GTK_OBJECT(dialog));
+       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);
-       gtk_signal_connect(GTK_OBJECT(entry), "activate",
-                          GTK_SIGNAL_FUNC(replace_with_supplied_word_cb), 
-                          gtkaspell);
-       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);
-       label = gtk_label_new(_("Holding down MOD1 key while pressing "
+       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);
+
+       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);
-       gtk_signal_connect(GTK_OBJECT(ok_button), "clicked",
-                       GTK_SIGNAL_FUNC(replace_with_supplied_word_cb), 
-                       gtkaspell);
-       gtk_signal_connect_object(GTK_OBJECT(ok_button), "clicked",
-                       GTK_SIGNAL_FUNC(gtk_widget_destroy), 
-                       GTK_OBJECT(dialog));
+       gtkut_stock_button_set_create(&confirm_area,
+                                     &cancel_button, GTK_STOCK_CANCEL,
+                                     &ok_button, GTK_STOCK_OK,
+                                     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);
 
-       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));
+       g_signal_connect(G_OBJECT(ok_button), "clicked",
+                        G_CALLBACK(replace_with_supplied_word_cb), 
+                        gtkaspell);
+       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);
+       g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked",
+                                G_CALLBACK(gtk_widget_destroy), 
+                                G_OBJECT(dialog));
 
        gtk_widget_grab_focus(entry);
 
@@ -1371,35 +1630,20 @@ static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
        gtk_widget_show_all(dialog);
 }
 
-void gtkaspell_uncheck_all(GtkAspell * gtkaspell) 
+static void gtkaspell_uncheck_all(GtkAspell * gtkaspell) 
 {
-       gint      origpos;
-       gchar    *text;
-       gfloat    adj_value;
-       GtkSText *gtktext;
+       GtkTextView *gtktext;
+       GtkTextBuffer *buffer;
+       GtkTextIter startiter, enditer;
        
        gtktext = gtkaspell->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);
-
-       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);
-
+       buffer = gtk_text_view_get_buffer(gtktext);
+       gtk_text_buffer_get_iter_at_offset(buffer, &startiter, 0);
+       gtk_text_buffer_get_iter_at_offset(buffer, &enditer,
+                                  get_textview_buffer_charcount(gtktext)-1);
+       gtk_text_buffer_remove_tag_by_name(buffer, "misspelled",
+                                          &startiter, &enditer);
 }
 
 static void toggle_check_while_typing_cb(GtkWidget *w, gpointer data)
@@ -1410,9 +1654,8 @@ static void toggle_check_while_typing_cb(GtkWidget *w, gpointer data)
 
        if (!gtkaspell->check_while_typing)
                gtkaspell_uncheck_all(gtkaspell);
-
-       if (gtkaspell->config_menu)
-               populate_submenu(gtkaspell, gtkaspell->config_menu);
+       if (gtkaspell->menu_changed_cb)
+               gtkaspell->menu_changed_cb(gtkaspell->menu_changed_data);
 }
 
 static GSList *create_empty_dictionary_list(void)
@@ -1429,7 +1672,7 @@ static GSList *create_empty_dictionary_list(void)
 }
 
 /* gtkaspell_get_dictionary_list() - returns list of dictionary names */
-GSList *gtkaspell_get_dictionary_list(const gchar *aspell_path, gint refresh)
+static GSList *gtkaspell_get_dictionary_list(const gchar *aspell_path, gint refresh)
 {
        GSList *list;
        Dictionary *dict;
@@ -1439,26 +1682,17 @@ GSList *gtkaspell_get_dictionary_list(const gchar *aspell_path, gint refresh)
        const AspellDictInfo *entry;
 
        if (!gtkaspellcheckers)
-               gtkaspellcheckers = gtkaspell_checkers_new();
+               gtkaspell_checkers_init();
 
        if (gtkaspellcheckers->dictionary_list && !refresh)
                return gtkaspellcheckers->dictionary_list;
        else
-               gtkaspell_free_dictionary_list(gtkaspellcheckers->dictionary_list);
+               gtkaspell_free_dictionary_list(
+                               gtkaspellcheckers->dictionary_list);
        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(
@@ -1472,7 +1706,7 @@ GSList *gtkaspell_get_dictionary_list(const gchar *aspell_path, gint refresh)
        dlist = get_aspell_dict_info_list(config);
        delete_aspell_config(config);
 
-       debug_print("Aspell: checking for dictionaries in %s\n", aspell_path);
+       debug_print("Aspell: checking for dictionaries in %s\n", aspell_path?aspell_path:"(null)");
        dels = aspell_dict_info_list_elements(dlist);
        while ( (entry = aspell_dict_info_enumeration_next(dels)) != 0) 
        {
@@ -1481,8 +1715,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);
        }
@@ -1501,7 +1742,7 @@ GSList *gtkaspell_get_dictionary_list(const gchar *aspell_path, gint refresh)
        return list;
 }
 
-void gtkaspell_free_dictionary_list(GSList *list)
+static void gtkaspell_free_dictionary_list(GSList *list)
 {
        Dictionary *dict;
        GSList *walk;
@@ -1513,102 +1754,131 @@ void gtkaspell_free_dictionary_list(GSList *list)
        g_slist_free(list);
 }
 
-GtkWidget *gtkaspell_dictionary_option_menu_new(const gchar *aspell_path)
+GtkTreeModel *gtkaspell_dictionary_store_new_with_refresh(const gchar *aspell_path,
+                                                            gboolean refresh)
 {
        GSList *dict_list, *tmp;
-       GtkWidget *item;
-       GtkWidget *menu;
+       GtkListStore *store;
+       GtkTreeIter iter;
        Dictionary *dict;
 
-       dict_list = gtkaspell_get_dictionary_list(aspell_path, TRUE);
+       dict_list = gtkaspell_get_dictionary_list(aspell_path, refresh);
        g_return_val_if_fail(dict_list, NULL);
 
-       menu = gtk_menu_new();
+       store = gtk_list_store_new(SET_GTKASPELL_SIZE,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  -1);
        
        for (tmp = dict_list; tmp != NULL; tmp = g_slist_next(tmp)) {
                dict = (Dictionary *) tmp->data;
-               item = gtk_menu_item_new_with_label(dict->dictname);
-               gtk_object_set_data(GTK_OBJECT(item), "dict_name",
-                                   dict->fullname); 
-                                        
-               gtk_menu_append(GTK_MENU(menu), item);                                   
-               gtk_widget_show(item);
+               
+               gtk_list_store_append(store, &iter);
+               gtk_list_store_set(store, &iter,
+                                  SET_GTKASPELL_NAME, dict->dictname,
+                                  SET_GTKASPELL_FULLNAME, dict->fullname,
+                                  -1);
        }
 
-       gtk_widget_show(menu);
-
-       return menu;
+       return GTK_TREE_MODEL(store);
 }
 
-gchar *gtkaspell_get_dictionary_menu_active_item(GtkWidget *menu)
+GtkTreeModel *gtkaspell_dictionary_store_new(const gchar *aspell_path)
 {
-       GtkWidget *menuitem;
-       gchar *dict_fullname;
-       gchar *label;
-
-       g_return_val_if_fail(GTK_IS_MENU(menu), NULL);
-
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-        dict_fullname = (gchar *) gtk_object_get_data(GTK_OBJECT(menuitem), 
-                                                     "dict_name");
-        g_return_val_if_fail(dict_fullname, NULL);
-
-       label = g_strdup(dict_fullname);
-
-        return label;
-  
+       return gtkaspell_dictionary_store_new_with_refresh
+               (aspell_path, TRUE);
 }
 
-GtkWidget *gtkaspell_sugmode_option_menu_new(gint sugmode)
+GtkWidget *gtkaspell_dictionary_combo_new(const gchar *aspell_path,
+                                         const gboolean refresh)
 {
-       GtkWidget *menu;
-       GtkWidget *item;
+       GtkWidget *combo;
+       GtkCellRenderer *renderer;
 
-       menu = gtk_menu_new();
-       gtk_widget_show(menu);
-
-       item = gtk_menu_item_new_with_label(_("Fast Mode"));
-        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu), item);
-       gtk_object_set_data(GTK_OBJECT(item), "sugmode", GINT_TO_POINTER(ASPELL_FASTMODE));
+       combo = gtk_combo_box_new_with_model(
+                       gtkaspell_dictionary_store_new_with_refresh(aspell_path, refresh));
+       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);   
+       gtk_widget_show(combo);
+       
+       renderer = gtk_cell_renderer_text_new();
+       gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
+       gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo),renderer,
+                                       "text", SET_GTKASPELL_NAME, NULL);
+       
+       return combo;
+} 
 
-       item = gtk_menu_item_new_with_label(_("Normal Mode"));
-        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu), item);
-       gtk_object_set_data(GTK_OBJECT(item), "sugmode", GINT_TO_POINTER(ASPELL_NORMALMODE));
+gchar *gtkaspell_get_dictionary_menu_active_item(GtkComboBox *combo)
+{
+       GtkTreeIter iter;
+       GtkTreeModel *model;
+       gchar *dict_fullname = NULL;
        
-       item = gtk_menu_item_new_with_label(_("Bad Spellers Mode"));
-        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu), item);
-       gtk_object_set_data(GTK_OBJECT(item), "sugmode", GINT_TO_POINTER(ASPELL_BADSPELLERMODE));
+       g_return_val_if_fail(GTK_IS_COMBO_BOX(combo), NULL);
+       g_return_val_if_fail(gtk_combo_box_get_active_iter(combo, &iter), NULL);
+       
+       model = gtk_combo_box_get_model(combo);
+       if(model == NULL)
+               return NULL;
+       
+       gtk_tree_model_get(model, &iter,
+                          SET_GTKASPELL_FULLNAME, &dict_fullname,
+                          -1);
 
-       return menu;
+        return dict_fullname;
 }
-       
-void gtkaspell_sugmode_option_menu_set(GtkOptionMenu *optmenu, gint sugmode)
-{
-       g_return_if_fail(GTK_IS_OPTION_MENU(optmenu));
 
-       g_return_if_fail(sugmode == ASPELL_FASTMODE ||
-                        sugmode == ASPELL_NORMALMODE ||
-                        sugmode == ASPELL_BADSPELLERMODE);
+gint gtkaspell_set_dictionary_menu_active_item(GtkComboBox *combo,
+                                              const gchar *dictionary)
+{
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       gchar *dict_name = NULL;
+       
+       g_return_val_if_fail(combo != NULL, 0);
+       g_return_val_if_fail(dictionary != NULL, 0);
+       g_return_val_if_fail(GTK_IS_COMBO_BOX(combo), 0);
 
-       gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), sugmode - 1);
+       if((model = gtk_combo_box_get_model(combo)) == NULL)
+               return 0;
+       if((gtk_tree_model_get_iter_first(model, &iter)) == FALSE)
+               return 0;
+       
+       do {
+               gtk_tree_model_get(model, &iter,
+                                  SET_GTKASPELL_FULLNAME, &dict_name,
+                                  -1);
+               
+               if ((dict_name != NULL) && !strcmp2(dict_name, dictionary)) {
+                       gtk_combo_box_set_active_iter(combo, &iter);
+                       g_free(dict_name);
+                       return 1;
+               }
+               
+               g_free(dict_name);
+               
+       } while ((gtk_tree_model_iter_next(model, &iter)) == TRUE);
+       
+       return 0;
 }
 
-gint gtkaspell_get_sugmode_from_option_menu(GtkOptionMenu *optmenu)
+GtkWidget *gtkaspell_sugmode_combo_new(gint sugmode)
 {
-       gint sugmode;
-       GtkWidget *item;
+       GtkWidget *combo = gtkut_sc_combobox_create(NULL, FALSE);
+       GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(
+                                               GTK_COMBO_BOX(combo)));
+       GtkTreeIter iter;
        
-       g_return_val_if_fail(GTK_IS_OPTION_MENU(optmenu), -1);
-
-       item = gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(optmenu)));
+       g_return_val_if_fail(store != NULL, NULL);
        
-       sugmode = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(item),
-                                                     "sugmode"));
+       COMBOBOX_ADD(store, _("Fast Mode"), ASPELL_FASTMODE);
+       COMBOBOX_ADD(store, _("Normal Mode"), ASPELL_NORMALMODE);
+       COMBOBOX_ADD(store, _("Bad Spellers Mode"), ASPELL_BADSPELLERMODE);
 
-       return sugmode;
+       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), sugmode - 1);
+       gtk_widget_show(combo);
+       
+       return combo;
 }
 
 static void use_alternate_dict(GtkAspell *gtkaspell)
@@ -1618,108 +1888,104 @@ static void use_alternate_dict(GtkAspell *gtkaspell)
        tmp = gtkaspell->gtkaspeller;
        gtkaspell->gtkaspeller = gtkaspell->alternate_speller;
        gtkaspell->alternate_speller = tmp;
-
-       if (gtkaspell->config_menu)
-               populate_submenu(gtkaspell, gtkaspell->config_menu);
 }
 
-static void popup_menu(GtkAspell *gtkaspell, GdkEventButton *eb) 
-{
-       GtkSText * gtktext;
-       
-       gtktext = gtkaspell->gtktext;
-       gtkaspell->orig_pos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
-
-       if (!(eb->state & GDK_SHIFT_MASK)) {
-               if (check_at(gtkaspell, gtkaspell->orig_pos)) {
+static void destroy_menu(GtkWidget *widget,
+                            gpointer user_data) {
 
-                       gtk_editable_set_position(GTK_EDITABLE(gtktext), 
-                                                 gtkaspell->orig_pos);
-                       gtk_stext_set_point(gtktext, gtkaspell->orig_pos);
+       GtkAspell *gtkaspell = (GtkAspell *)user_data;
 
-                       if (misspelled_suggest(gtkaspell, gtkaspell->theword)) {
-                               gtk_menu_popup(make_sug_menu(gtkaspell), 
-                                              NULL, NULL, NULL, NULL,
-                                              eb->button, GDK_CURRENT_TIME);
-                               
-                               return;
-                       }
-               } else {
-                       gtk_editable_set_position(GTK_EDITABLE(gtktext), 
-                                                 gtkaspell->orig_pos);
-                       gtk_stext_set_point(gtktext, gtkaspell->orig_pos);
-               }
+       if (gtkaspell->accel_group) {
+               gtk_window_remove_accel_group(GTK_WINDOW(gtkaspell->parent_window), 
+                               gtkaspell->accel_group);
+               gtkaspell->accel_group = NULL;
        }
+}
 
-       gtk_menu_popup(make_config_menu(gtkaspell), NULL, NULL, NULL, NULL,
-                      eb->button, GDK_CURRENT_TIME);
+static gboolean aspell_key_pressed(GtkWidget *widget,
+                                  GdkEventKey *event,
+                                  GtkAspell *gtkaspell)
+{
+       if (event && (isascii(event->keyval) || event->keyval == GDK_Return)) {
+               gtk_accel_groups_activate(
+                               G_OBJECT(gtkaspell->parent_window),
+                               event->keyval, event->state);
+       } else if (event && event->keyval == GDK_Escape) {
+               destroy_menu(NULL, gtkaspell);
+       }
+       return FALSE;
 }
 
 /* make_sug_menu() - Add menus to accept this word for this session 
  * and to add it to personal dictionary 
  */
-static GtkMenu *make_sug_menu(GtkAspell *gtkaspell) 
+static GSList *make_sug_menu(GtkAspell *gtkaspell) 
 {
-       GtkWidget       *menu, *item;
-       unsigned char   *caption;
-       GtkSText        *gtktext;
+       GtkWidget       *item;
+       char    *caption;
+       GtkTextView     *gtktext;
        GtkAccelGroup   *accel;
        GList           *l = gtkaspell->suggestions_list;
-
+       gchar           *utf8buf;
+       GSList *list = NULL;
        gtktext = gtkaspell->gtktext;
 
        accel = gtk_accel_group_new();
-       menu = gtk_menu_new(); 
 
-       if (gtkaspell->sug_menu)
-               gtk_widget_destroy(gtkaspell->sug_menu);
-
-       gtkaspell->sug_menu = menu;     
-
-       gtk_signal_connect(GTK_OBJECT(menu), "cancel",
-               GTK_SIGNAL_FUNC(cancel_menu_cb), gtkaspell);
+       if (gtkaspell->accel_group) {
+               gtk_window_remove_accel_group(GTK_WINDOW(gtkaspell->parent_window), 
+                               gtkaspell->accel_group);
+               gtkaspell->accel_group = NULL;
+       }
 
+       utf8buf  = conv_codeset_strdup((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);
+       list = g_slist_append(list, item);
        gtk_misc_set_alignment(GTK_MISC(GTK_BIN(item)->child), 0.5, 0.5);
        g_free(caption);
 
        item = gtk_menu_item_new();
        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu), item);
+       list = g_slist_append(list, item);
 
        item = gtk_menu_item_new_with_label(_("Accept in this session"));
        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_cb), 
-                          gtkaspell);
+       list = g_slist_append(list, item);
+        g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(add_word_to_session_cb), 
+                        gtkaspell);
        gtk_widget_add_accelerator(item, "activate", accel, GDK_space,
-                                  GDK_MOD1_MASK,
+                                  GDK_CONTROL_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_cb), 
-                          gtkaspell);
+       list = g_slist_append(list, item);
+        g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(add_word_to_personal_cb), 
+                        gtkaspell);
        gtk_widget_add_accelerator(item, "activate", accel, GDK_Return,
-                                  GDK_MOD1_MASK,
+                                  GDK_CONTROL_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_create_dialog_cb), 
-                          gtkaspell);
+       list = g_slist_append(list, item);
+        g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(replace_with_create_dialog_cb), 
+                        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"), 
@@ -1727,25 +1993,28 @@ static GtkMenu *make_sug_menu(GtkAspell *gtkaspell)
                item = gtk_menu_item_new_with_label(caption);
                g_free(caption);
                gtk_widget_show(item);
-               gtk_menu_append(GTK_MENU(menu), item);
-               gtk_signal_connect(GTK_OBJECT(item), "activate",
-                               GTK_SIGNAL_FUNC(check_with_alternate_cb),
-                               gtkaspell);
+               list = g_slist_append(list, item);
+               g_signal_connect(G_OBJECT(item), "activate",
+                                G_CALLBACK(check_with_alternate_cb),
+                                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();
         gtk_widget_show(item);
-        gtk_menu_append(GTK_MENU(menu), item);
+        list = g_slist_append(list, item);
 
        l = l->next;
         if (l == NULL) {
                item = gtk_menu_item_new_with_label(_("(no suggestions)"));
                gtk_widget_show(item);
-               gtk_menu_append(GTK_MENU(menu), item);
+               list = g_slist_append(list, item);
         } else {
-               GtkWidget *curmenu = menu;
+               GtkWidget *curmenu = NULL;
                gint count = 0;
                
                do {
@@ -1754,21 +2023,32 @@ static GtkMenu *make_sug_menu(GtkAspell *gtkaspell)
 
                                item = gtk_menu_item_new_with_label(_("More..."));
                                gtk_widget_show(item);
-                               gtk_menu_append(GTK_MENU(curmenu), item);
+                               if (curmenu)
+                                       gtk_menu_append(GTK_MENU(curmenu), item);
+                               else 
+                                       list = g_slist_append(list, 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);
+                       utf8buf  = conv_codeset_strdup((char*)l->data,
+                                                       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);
-                       gtk_signal_connect(GTK_OBJECT(item), "activate",
-                                          GTK_SIGNAL_FUNC(replace_word_cb),
-                                          gtkaspell);
+                       if (curmenu == NULL) {
+                               list = g_slist_append(list, item);
+                       } else {
+                               gtk_menu_append(GTK_MENU(curmenu), item);
+                       }
+                       g_signal_connect(G_OBJECT(item), "activate",
+                                        G_CALLBACK(replace_word_cb),
+                                        gtkaspell);
 
-                       if (curmenu == menu && count < MENUCOUNT) {
+                       if (curmenu == NULL && count < MENUCOUNT) {
                                gtk_widget_add_accelerator(item, "activate",
                                                           accel,
                                                           GDK_A + count, 0,
@@ -1777,7 +2057,7 @@ static GtkMenu *make_sug_menu(GtkAspell *gtkaspell)
                                gtk_widget_add_accelerator(item, "activate", 
                                                           accel,
                                                           GDK_A + count, 
-                                                          GDK_MOD1_MASK,
+                                                          GDK_CONTROL_MASK,
                                                           GTK_ACCEL_LOCKED);
                                }
 
@@ -1786,108 +2066,123 @@ static GtkMenu *make_sug_menu(GtkAspell *gtkaspell)
                } while ((l = l->next) != NULL);
        }
 
-       gtk_accel_group_attach(accel, GTK_OBJECT(menu));
-       gtk_accel_group_unref(accel);
-       
-       return GTK_MENU(menu);
+       gtk_window_add_accel_group
+               (GTK_WINDOW(gtkaspell->parent_window),
+                accel);
+       gtkaspell->accel_group = accel;
+
+       return list;
 }
 
-static void populate_submenu(GtkAspell *gtkaspell, GtkWidget *menu)
+static GSList *populate_submenu(GtkAspell *gtkaspell)
 {
        GtkWidget *item, *submenu;
        gchar *dictname;
-       GtkAspeller *gtkaspeller = gtkaspell->gtkaspeller;
-
-       if (GTK_MENU_SHELL(menu)->children) {
-               GList *amenu, *alist;
-               for (amenu = (GTK_MENU_SHELL(menu)->children); amenu; ) {
-                       alist = amenu->next;
-                       gtk_widget_destroy(GTK_WIDGET(amenu->data));
-                       amenu = alist;
-               }
-       }
-       
+       GtkAspeller *gtkaspeller = NULL;
+       GSList *list = NULL;
+
+       if (!gtkaspell)
+               return NULL;
+
+       gtkaspeller = gtkaspell->gtkaspeller;
        dictname = g_strdup_printf(_("Dictionary: %s"),
                                   gtkaspeller->dictionary->dictname);
        item = gtk_menu_item_new_with_label(dictname);
        gtk_misc_set_alignment(GTK_MISC(GTK_BIN(item)->child), 0.5, 0.5);
        g_free(dictname);
        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu), item);
+       list = g_slist_append(list, item);
 
        item = gtk_menu_item_new();
         gtk_widget_show(item);
-        gtk_menu_append(GTK_MENU(menu), item);
+        list = g_slist_append(list, item);
                
        if (gtkaspell->use_alternate && gtkaspell->alternate_speller) {
                dictname = g_strdup_printf(_("Use alternate (%s)"), 
                                gtkaspell->alternate_speller->dictionary->dictname);
                item = gtk_menu_item_new_with_label(dictname);
                g_free(dictname);
-               gtk_signal_connect(GTK_OBJECT(item), "activate",
-                                  GTK_SIGNAL_FUNC(switch_to_alternate_cb),
-                                  gtkaspell);
+               g_signal_connect(G_OBJECT(item), "activate",
+                                G_CALLBACK(switch_to_alternate_cb),
+                                gtkaspell);
                gtk_widget_show(item);
-               gtk_menu_append(GTK_MENU(menu), item);
+               list = g_slist_append(list, item);
        }
 
+       item = gtk_check_menu_item_new_with_label(_("Use both dictionaries"));
+       if (gtkaspell->use_both_dicts) {
+               gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
+       } 
+       g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(set_use_both_cb),
+                        gtkaspell);
+       gtk_widget_show(item);
+       list = g_slist_append(list, item);
+       
+       item = gtk_menu_item_new();
+        gtk_widget_show(item);
+        list = g_slist_append(list, item);
+       
        item = gtk_check_menu_item_new_with_label(_("Fast Mode"));
+       gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), TRUE);
        if (gtkaspell->gtkaspeller->sug_mode == ASPELL_FASTMODE) {
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),TRUE);
                gtk_widget_set_sensitive(GTK_WIDGET(item),FALSE);
        } else
-               gtk_signal_connect(GTK_OBJECT(item), "activate",
-                                  GTK_SIGNAL_FUNC(set_sug_mode_cb),
-                                  gtkaspell);
+               g_signal_connect(G_OBJECT(item), "activate",
+                                G_CALLBACK(set_sug_mode_cb),
+                                gtkaspell);
        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu), item);
+       list = g_slist_append(list, item);
 
        item = gtk_check_menu_item_new_with_label(_("Normal Mode"));
+       gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), TRUE);
        if (gtkaspell->gtkaspeller->sug_mode == ASPELL_NORMALMODE) {
                gtk_widget_set_sensitive(GTK_WIDGET(item), FALSE);
                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),
-                                  gtkaspell);
+               g_signal_connect(G_OBJECT(item), "activate",
+                                G_CALLBACK(set_sug_mode_cb),
+                                gtkaspell);
        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu),item);
+       list = g_slist_append(list, item);
 
        item = gtk_check_menu_item_new_with_label(_("Bad Spellers Mode"));
+       gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), TRUE);
        if (gtkaspell->gtkaspeller->sug_mode == ASPELL_BADSPELLERMODE) {
                gtk_widget_set_sensitive(GTK_WIDGET(item), FALSE);
                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),
-                                  gtkaspell);
+               g_signal_connect(G_OBJECT(item), "activate",
+                                G_CALLBACK(set_sug_mode_cb),
+                                gtkaspell);
        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu), item);
+       list = g_slist_append(list, item);
        
        item = gtk_menu_item_new();
         gtk_widget_show(item);
-        gtk_menu_append(GTK_MENU(menu), item);
+        list = g_slist_append(list, item);
        
        item = gtk_check_menu_item_new_with_label(_("Check while typing"));
        if (gtkaspell->check_while_typing)
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
        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_cb),
-                          gtkaspell);
+       g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(toggle_check_while_typing_cb),
+                        gtkaspell);
        gtk_widget_show(item);
-       gtk_menu_append(GTK_MENU(menu), item);
+       list = g_slist_append(list, item);
 
        item = gtk_menu_item_new();
         gtk_widget_show(item);
-        gtk_menu_append(GTK_MENU(menu), item);
+        list = g_slist_append(list, item);
 
        submenu = gtk_menu_new();
         item = gtk_menu_item_new_with_label(_("Change dictionary"));
         gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),submenu);
         gtk_widget_show(item);
-        gtk_menu_append(GTK_MENU(menu), item);
+        list = g_slist_append(list, item);
 
        /* Dict list */
         if (gtkaspellcheckers->dictionary_list == NULL)
@@ -1916,8 +2211,8 @@ static void populate_submenu(GtkAspell *gtkaspell, GtkWidget *menu)
                        }
                        dict = (Dictionary *) tmp->data;
                        item = gtk_check_menu_item_new_with_label(dict->dictname);
-                       gtk_object_set_data(GTK_OBJECT(item), "dict_name",
-                                           dict->fullname); 
+                       g_object_set_data(G_OBJECT(item), "dict_name",
+                                         dict->fullname); 
                        if (strcmp2(dict->fullname,
                            gtkaspell->gtkaspeller->dictionary->fullname))
                                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), FALSE);
@@ -1926,128 +2221,109 @@ static void populate_submenu(GtkAspell *gtkaspell, GtkWidget *menu)
                                gtk_widget_set_sensitive(GTK_WIDGET(item),
                                                         FALSE);
                        }
-                       gtk_signal_connect(GTK_OBJECT(item), "activate",
-                                          GTK_SIGNAL_FUNC(change_dict_cb),
-                                          gtkaspell);
+                       g_signal_connect(G_OBJECT(item), "activate",
+                                        G_CALLBACK(change_dict_cb),
+                                        gtkaspell);
                        gtk_widget_show(item);
                        gtk_menu_append(GTK_MENU(curmenu), item);
                        
                        count++;
                }
         }  
+       return list;
 }
 
-static GtkMenu *make_config_menu(GtkAspell *gtkaspell)
-{
-       if (!gtkaspell->popup_config_menu)
-               gtkaspell->popup_config_menu = gtk_menu_new();
-
-       debug_print("Aspell: creating/using popup_config_menu %0x\n", 
-                       (guint) gtkaspell->popup_config_menu);
-       populate_submenu(gtkaspell, gtkaspell->popup_config_menu);
-
-        return GTK_MENU(gtkaspell->popup_config_menu);
-}
-
-void gtkaspell_populate_submenu(GtkAspell *gtkaspell, GtkWidget *menuitem)
+GSList *gtkaspell_make_config_menu(GtkAspell *gtkaspell)
 {
-       GtkWidget *menu;
-
-       menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
-       
-       debug_print("Aspell: using config menu %0x\n", 
-                       (guint) gtkaspell->popup_config_menu);
-       populate_submenu(gtkaspell, menu);
-       
-       gtkaspell->config_menu = menu;
-       
+       return populate_submenu(gtkaspell);
 }
 
-static void set_menu_pos(GtkMenu *menu, gint *x, gint *y, gpointer data)
+static void set_menu_pos(GtkMenu *menu, gint *x, gint *y, 
+                        gboolean *push_in, gpointer data)
 {
        GtkAspell       *gtkaspell = (GtkAspell *) data;
        gint             xx = 0, yy = 0;
        gint             sx,     sy;
        gint             wx,     wy;
-       GtkSText        *text = GTK_STEXT(gtkaspell->gtktext);
+       GtkTextView     *text = GTK_TEXT_VIEW(gtkaspell->gtktext);
+       GtkTextBuffer   *textbuf;
+       GtkTextIter      iter;
+       GdkRectangle     rect;
        GtkRequisition   r;
 
+       textbuf = gtk_text_view_get_buffer(gtkaspell->gtktext);
+       gtk_text_buffer_get_iter_at_mark(textbuf, &iter,
+                                        gtk_text_buffer_get_insert(textbuf));
+       gtk_text_view_get_iter_location(gtkaspell->gtktext, &iter, &rect);
+       gtk_text_view_buffer_to_window_coords(text, GTK_TEXT_WINDOW_TEXT,
+                                             rect.x, rect.y, 
+                                             &rect.x, &rect.y);
+
        gdk_window_get_origin(GTK_WIDGET(gtkaspell->gtktext)->window, &xx, &yy);
-       
+
        sx = gdk_screen_width();
        sy = gdk_screen_height();
-       
+
        gtk_widget_get_child_requisition(GTK_WIDGET(menu), &r);
-       
+
        wx =  r.width;
        wy =  r.height;
-       
-       *x = gtkaspell->gtktext->cursor_pos_x + xx +
-            gdk_char_width(GTK_WIDGET(text)->style->font, ' ');
-       *y = gtkaspell->gtktext->cursor_pos_y + yy;
+
+       *x = rect.x + xx +
+            gdk_char_width(gtk_style_get_font(GTK_WIDGET(text)->style), ' ');
+
+       *y = rect.y + rect.height + yy;
 
        if (*x + wx > sx)
                *x = sx - wx;
        if (*y + wy > sy)
-               *y = *y - wy - 
-                    gdk_string_height((GTK_WIDGET(gtkaspell->gtktext))->style->font, 
+               *y = *y - wy -
+                    gdk_string_height(gtk_style_get_font(
+                                               GTK_WIDGET(text)->style),
                                       gtkaspell->theword);
-
-}
-
-/* Menu call backs */
-
-static gboolean cancel_menu_cb(GtkMenuShell *w, gpointer data)
-{
-       GtkAspell *gtkaspell = (GtkAspell *) data;
-
-       gtkaspell->continue_check = NULL;
-       set_point_continue(gtkaspell);
-
-       return FALSE;
-       
 }
 
-/* change_dict_cb() - Menu callback : change dict */
-static void change_dict_cb(GtkWidget *w, GtkAspell *gtkaspell)
+/* change the current dictionary of gtkaspell
+   - if always_set_alt_dict is set, the alternate dict is unconditionally set to the former
+     current dictionary (common use: from menu callbacks)
+   - if always_set_alt_dict is NOT set, the alternate dict will be set to the former
+     current dictionary only if there is no alternate dictionary already set
+     (this is when we need to set the current dictionary then the alternate one
+     when creating a compose window, from the account and folder settings)
+*/
+gboolean gtkaspell_change_dict(GtkAspell *gtkaspell, const gchar *dictionary,
+                                                        gboolean always_set_alt_dict)
 {
        Dictionary      *dict;       
-       gchar           *fullname;
        GtkAspeller     *gtkaspeller;
        gint             sug_mode;
-  
-        fullname = (gchar *) gtk_object_get_data(GTK_OBJECT(w), "dict_name");
-       
-       if (!strcmp2(fullname, _("None")))
-               return;
 
+       g_return_val_if_fail(gtkaspell, FALSE);
+       g_return_val_if_fail(dictionary, FALSE);
+  
        sug_mode  = gtkaspell->default_sug_mode;
 
        dict = g_new0(Dictionary, 1);
-       dict->fullname = g_strdup(fullname);
+       dict->fullname = g_strdup(dictionary);
        dict->encoding = g_strdup(gtkaspell->gtkaspeller->dictionary->encoding);
 
-       if (gtkaspell->use_alternate && gtkaspell->alternate_speller &&
-           dict == gtkaspell->alternate_speller->dictionary) {
-               use_alternate_dict(gtkaspell);
-               dictionary_delete(dict);
-               return;
-       }
-       
        gtkaspeller = gtkaspeller_new(dict);
 
        if (!gtkaspeller) {
-               gchar *message;
-               message = g_strdup_printf(_("The spell checker could not change dictionary.\n%s"), 
+               alertpanel_warning(_("The spell checker could not change dictionary.\n%s"), 
                                          gtkaspellcheckers->error_message);
-
-               gtkaspell_alert_dialog(message); 
-               g_free(message);
        } else {
                if (gtkaspell->use_alternate) {
-                       if (gtkaspell->alternate_speller)
-                               gtkaspeller_delete(gtkaspell->alternate_speller);
-                       gtkaspell->alternate_speller = gtkaspell->gtkaspeller;
+                       if (gtkaspell->alternate_speller) {
+                               if (always_set_alt_dict) {
+                                       gtkaspeller_delete(gtkaspell->alternate_speller);
+                                       gtkaspell->alternate_speller = gtkaspell->gtkaspeller;
+                               } else
+                                       gtkaspeller_delete(gtkaspell->gtkaspeller);
+                       } else
+                               /* should never be reached as the dicts are always set
+                                  to a default value */
+                               gtkaspell->alternate_speller = gtkaspell->gtkaspeller;
                } else
                        gtkaspeller_delete(gtkaspell->gtkaspeller);
 
@@ -2057,8 +2333,56 @@ static void change_dict_cb(GtkWidget *w, GtkAspell *gtkaspell)
        
        dictionary_delete(dict);
 
-       if (gtkaspell->config_menu)
-               populate_submenu(gtkaspell, gtkaspell->config_menu);
+       return TRUE;    
+}
+
+/* change the alternate dictionary of gtkaspell (doesn't affect the default dictionary) */
+gboolean gtkaspell_change_alt_dict(GtkAspell *gtkaspell, const gchar *alt_dictionary)
+{
+       Dictionary      *dict;       
+       GtkAspeller     *gtkaspeller;
+
+       g_return_val_if_fail(gtkaspell, FALSE);
+       g_return_val_if_fail(alt_dictionary, FALSE);
+  
+       dict = g_new0(Dictionary, 1);
+       dict->fullname = g_strdup(alt_dictionary);
+       dict->encoding = g_strdup(gtkaspell->gtkaspeller->dictionary->encoding);
+
+       gtkaspeller = gtkaspeller_new(dict);
+
+       if (!gtkaspeller) {
+               alertpanel_warning(_("The spell checker could not change the alternate dictionary.\n%s"), 
+                                         gtkaspellcheckers->error_message);
+       } else {
+               if (gtkaspell->alternate_speller)
+                       gtkaspeller_delete(gtkaspell->alternate_speller);
+               gtkaspell->alternate_speller = gtkaspeller;
+       }
+       
+       dictionary_delete(dict);
+
+       return TRUE;    
+}
+
+/* Menu call backs */
+
+/* change_dict_cb() - Menu callback : change dict */
+static void change_dict_cb(GtkWidget *w, GtkAspell *gtkaspell)
+{
+       gchar           *fullname;
+  
+        fullname = (gchar *) g_object_get_data(G_OBJECT(w), "dict_name");
+       
+       if (!strcmp2(fullname, _("None")))
+               return;
+
+       gtkaspell_change_dict(gtkaspell, fullname, TRUE);
+       if (gtkaspell->recheck_when_changing_dict) {
+               gtkaspell_highlight_all(gtkaspell);
+       }
+       if (gtkaspell->menu_changed_cb)
+               gtkaspell->menu_changed_cb(gtkaspell->menu_changed_data);
 }
 
 static void switch_to_alternate_cb(GtkWidget *w,
@@ -2066,20 +2390,22 @@ static void switch_to_alternate_cb(GtkWidget *w,
 {
        GtkAspell *gtkaspell = (GtkAspell *) data;
        use_alternate_dict(gtkaspell);
+       if (gtkaspell->recheck_when_changing_dict) {
+               gtkaspell_highlight_all(gtkaspell);
+       }
+       if (gtkaspell->menu_changed_cb)
+               gtkaspell->menu_changed_cb(gtkaspell->menu_changed_data);
 }
 
 /* Misc. helper functions */
 
 static void set_point_continue(GtkAspell *gtkaspell)
 {
-       GtkSText  *gtktext;
+       GtkTextView  *gtktext;
 
        gtktext = gtkaspell->gtktext;
 
-       gtk_stext_freeze(gtktext);
-       gtk_editable_set_position(GTK_EDITABLE(gtktext),gtkaspell->orig_pos);
-       gtk_stext_set_point(gtktext, gtkaspell->orig_pos);
-       gtk_stext_thaw(gtktext);
+       set_textview_buffer_offset(gtktext, gtkaspell->orig_pos);
 
        if (gtkaspell->continue_check)
                gtkaspell->continue_check((gpointer *) gtkaspell);
@@ -2087,14 +2413,9 @@ static void set_point_continue(GtkAspell *gtkaspell)
 
 static void allocate_color(GtkAspell *gtkaspell, gint rgbvalue)
 {
-       GdkColormap *gc;
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer(gtkaspell->gtktext);
        GdkColor *color = &(gtkaspell->highlight);
 
-       gc = gtk_widget_get_colormap(GTK_WIDGET(gtkaspell->gtktext));
-
-       if (gtkaspell->highlight.pixel)
-               gdk_colormap_free_colors(gc, &(gtkaspell->highlight), 1);
-
        /* Shameless copy from Sylpheed's gtkutils.c */
        color->pixel = 0L;
        color->red   = (int) (((gdouble)((rgbvalue & 0xff0000) >> 16) / 255.0)
@@ -2104,7 +2425,13 @@ static void allocate_color(GtkAspell *gtkaspell, gint rgbvalue)
        color->blue  = (int) (((gdouble) (rgbvalue & 0x0000ff)        / 255.0)
                        * 65535.0);
 
-       gdk_colormap_alloc_color(gc, &(gtkaspell->highlight), FALSE, TRUE);
+       if (rgbvalue != 0)
+               gtk_text_buffer_create_tag(buffer, "misspelled",
+                                  "foreground-gdk", color, NULL);
+       else
+               gtk_text_buffer_create_tag(buffer, "misspelled",
+                                  "underline", PANGO_UNDERLINE_ERROR, NULL);
+
 }
 
 static void change_color(GtkAspell * gtkaspell, 
@@ -2112,29 +2439,35 @@ static void change_color(GtkAspell * gtkaspell,
                         gchar *newtext,
                          GdkColor *color) 
 {
-       GtkSText *gtktext;
+       GtkTextView *gtktext;
+       GtkTextBuffer *buffer;
+       GtkTextIter startiter, enditer;
 
-       g_return_if_fail(start < end);
+       if (start > end)
+               return;
     
        gtktext = gtkaspell->gtktext;
     
-       gtk_stext_freeze(gtktext);
-       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);
+       buffer = gtk_text_view_get_buffer(gtktext);
+       gtk_text_buffer_get_iter_at_offset(buffer, &startiter, start);
+       gtk_text_buffer_get_iter_at_offset(buffer, &enditer, end);
+       if (color)
+               gtk_text_buffer_apply_tag_by_name(buffer, "misspelled",
+                                                 &startiter, &enditer);
+       else {
+               gtk_text_iter_forward_char(&enditer);
+               gtk_text_buffer_remove_tag_by_name(buffer, "misspelled",
+                                                  &startiter, &enditer);
        }
-       gtk_stext_thaw(gtktext);
 }
 
 /* convert_to_aspell_encoding () - converts ISO-8859-* strings to iso8859-* 
  * as needed by aspell. Returns an allocated string.
  */
 
-static guchar *convert_to_aspell_encoding (const guchar *encoding)
+static gchar *convert_to_aspell_encoding (const gchar *encoding)
 {
-       guchar * aspell_encoding;
+       gchar * aspell_encoding;
 
        if (strstr2(encoding, "ISO-8859-")) {
                aspell_encoding = g_strdup_printf("iso8859%s", encoding+8);
@@ -2201,7 +2534,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;
@@ -2239,40 +2572,12 @@ static gint find_gtkaspeller(gconstpointer aa, gconstpointer bb)
        return 1;
 }
 
-static void gtkaspell_alert_dialog(gchar *message)
+gchar *gtkaspell_get_default_dictionary(GtkAspell *gtkaspell)
 {
-       GtkWidget *dialog;
-       GtkWidget *hbox;
-       GtkWidget *label;
-       GtkWidget *ok_button;
-
-       dialog = gtk_dialog_new();
-       gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
-       gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_MOUSE);
-       gtk_signal_connect_object(GTK_OBJECT(dialog), "destroy",
-                                  GTK_SIGNAL_FUNC(gtk_widget_destroy), 
-                                  GTK_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);    
-
-       gtk_signal_connect_object(GTK_OBJECT(ok_button), "clicked",
-                                  GTK_SIGNAL_FUNC(gtk_widget_destroy), 
-                                  GTK_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);
+       if (gtkaspell && gtkaspell->gtkaspeller &&
+                       gtkaspell->gtkaspeller->dictionary)
+               return gtkaspell->gtkaspeller->dictionary->dictname;
+       else
+               return NULL;
 }
 #endif