Fixed compile-time warnings
[claws.git] / src / gtkspell.c
index 09e3bff83b0534c81e53769746b8e34c91dd39a7..5da47a818f015154f060c9f20a1d4f608d348517 100644 (file)
@@ -132,6 +132,9 @@ static void                 replace_word_cb                 (GtkWidget *w,
                                                         gpointer data); 
 static void            replace_real_word               (GtkPspell *gtkpspell, 
                                                         gchar *newword);
+static void            check_with_alternate_cb         (GtkWidget *w,
+                                                        gpointer data);
+static void            use_alternate_dict              (GtkPspell *gtkpspell);
 static void            toggle_check_while_typing_cb    (GtkWidget *w, 
                                                         gpointer data);
 
@@ -151,6 +154,8 @@ static gboolean     cancel_menu_cb                  (GtkMenuShell *w,
                                                         gpointer data);
 static void            change_dict_cb                  (GtkWidget *w, 
                                                         GtkPspell *gtkpspell);
+static void            switch_to_alternate_cb          (GtkWidget *w, 
+                                                        gpointer data);
 
 /* Misc. helper functions */
 static void            set_point_continue              (GtkPspell *gtkpspell);
@@ -256,6 +261,7 @@ GtkPspell *gtkpspell_new(const gchar *dictionary,
                         const gchar *encoding,
                         gint  misspelled_color,
                         gboolean check_while_typing,
+                        gboolean use_alternate,
                         GtkSText *gtktext)
 {
        Dictionary      *dict = g_new0(Dictionary, 1);
@@ -275,6 +281,7 @@ GtkPspell *gtkpspell_new(const gchar *dictionary,
        gtkpspell = g_new(GtkPspell, 1);
 
        gtkpspell->gtkpspeller        = gtkpspeller;
+       gtkpspell->alternate_speller  = NULL;
        gtkpspell->theword[0]         = 0x00;
        gtkpspell->start_pos          = 0;
        gtkpspell->end_pos            = 0;
@@ -291,6 +298,7 @@ GtkPspell *gtkpspell_new(const gchar *dictionary,
        gtkpspell->default_sug_mode   = PSPELL_FASTMODE;
        gtkpspell->max_sug            = -1;
        gtkpspell->suggestions_list   = NULL;
+       gtkpspell->use_alternate      = use_alternate;
 
        allocate_color(gtkpspell, misspelled_color);
 
@@ -301,7 +309,7 @@ GtkPspell *gtkpspell_new(const gchar *dictionary,
        gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event",
                           GTK_SIGNAL_FUNC(button_press_intercept_cb), gtkpspell);
        
-       debug_print("Pspell: created gtkpspell %0x\n", gtkpspell);
+       debug_print("Pspell: created gtkpspell %0x\n", (guint) gtkpspell);
 
        return gtkpspell;
 }
@@ -324,6 +332,9 @@ void gtkpspell_delete(GtkPspell * gtkpspell)
        
        gtkpspeller_delete(gtkpspell->gtkpspeller);
 
+       if (gtkpspell->use_alternate && gtkpspell->alternate_speller)
+               gtkpspeller_delete(gtkpspell->alternate_speller);
+
        if (gtkpspell->sug_menu)
                gtk_widget_destroy(gtkpspell->sug_menu);
        if (gtkpspell->popup_config_menu)
@@ -333,7 +344,7 @@ void gtkpspell_delete(GtkPspell * gtkpspell)
        if (gtkpspell->suggestions_list)
                free_suggestions_list(gtkpspell);
        
-       debug_print("Pspell: deleting gtkpspell %0x\n", gtkpspell);
+       debug_print("Pspell: deleting gtkpspell %0x\n", (guint) gtkpspell);
 
        g_free(gtkpspell);
 
@@ -580,6 +591,8 @@ static GtkPspeller *gtkpspeller_real_delete(GtkPspeller *gtkpspeller)
 
        dictionary_delete(gtkpspeller->dictionary);
 
+       debug_print(_("Pspell: gtkpspeller %0x deleted.\n"), 
+                   (gint) gtkpspeller);
        g_free(gtkpspeller);
 
        return NULL;
@@ -736,7 +749,7 @@ gboolean gtkpspell_set_sug_mode(GtkPspell *gtkpspell, gint themode)
        g_return_val_if_fail(gtkpspell->gtkpspeller->config, FALSE);
 
        debug_print("Pspell: setting sug mode of gtkpspeller %0x to %d\n",
-                       gtkpspell->gtkpspeller, themode);
+                       (guint) gtkpspell->gtkpspeller, themode);
        config = gtkpspell->gtkpspeller->config;
        switch (themode) {
                case PSPELL_FASTMODE: 
@@ -1033,7 +1046,6 @@ static void continue_check(gpointer *data)
 {
        GtkPspell *gtkpspell = (GtkPspell *) data;
        gint pos = gtk_editable_get_position(GTK_EDITABLE(gtkpspell->gtktext));
-       
        if (pos < gtkpspell->end_check_pos && gtkpspell->misspelled)
                gtkpspell->misspelled = check_next_prev(gtkpspell, TRUE);
        else
@@ -1251,13 +1263,35 @@ static void add_word_to_personal_cb(GtkWidget *w, gpointer data)
        set_point_continue(gtkpspell);
 }
 
-static void deactivate_sug_menu_cb(GtkObject *w, gpointer data)
+static void check_with_alternate_cb(GtkWidget *w,
+                                   gpointer data)
 {
-       GtkMenuShell *menu_shell = GTK_MENU_SHELL(data);
-       debug_print("Destroying %0x\n", w);
-       gtk_menu_shell_deactivate(menu_shell);
-}
+       GtkPspell *gtkpspell = (GtkPspell *) data;
+       gint misspelled;
+       gtk_menu_shell_deactivate(GTK_MENU_SHELL(GTK_WIDGET(w)->parent));
 
+       use_alternate_dict(gtkpspell);
+       misspelled = check_at(gtkpspell, gtkpspell->start_pos);
+
+       if (!gtkpspell->continue_check) {
+               gtkpspell->misspelled = misspelled;
+               if (gtkpspell->misspelled) {
+                       misspelled_suggest(gtkpspell, gtkpspell->theword);
+                       gtk_stext_set_point(GTK_STEXT(gtkpspell->gtktext),
+                                           gtkpspell->end_pos);
+                       gtk_editable_set_position(GTK_EDITABLE(gtkpspell->gtktext),
+                                                 gtkpspell->end_pos);
+                       gtk_menu_popup(make_sug_menu(gtkpspell), NULL, NULL, 
+                                      set_menu_pos, gtkpspell, 0, 
+                                      GDK_CURRENT_TIME);
+                       return;
+               }
+       } else
+               gtkpspell->orig_pos = gtkpspell->start_pos;
+
+       set_point_continue(gtkpspell);
+}
+       
 static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
 {
        GtkWidget *dialog;
@@ -1588,6 +1622,20 @@ gint gtkpspell_get_sugmode_from_option_menu(GtkOptionMenu *optmenu)
        return sugmode;
        
 }
+
+static void use_alternate_dict(GtkPspell *gtkpspell)
+{
+       GtkPspeller *tmp;
+
+       tmp = gtkpspell->gtkpspeller;
+       gtkpspell->gtkpspeller = gtkpspell->alternate_speller;
+       gtkpspell->alternate_speller = tmp;
+
+       if (gtkpspell->config_menu)
+               populate_submenu(gtkpspell, gtkpspell->config_menu);
+}
+
+
 #if 0 /* Experimenal */
 void gtkpspell_set_primary_dict(GtkPspell *gtkpspell, gchar *dict, gchar *encoding)
 {
@@ -1709,8 +1757,9 @@ static GtkMenu *make_sug_menu(GtkPspell *gtkpspell)
        gtk_signal_connect(GTK_OBJECT(menu), "cancel",
                GTK_SIGNAL_FUNC(cancel_menu_cb), gtkpspell);
 
-       caption = g_strdup_printf(_("Unknown word: \"%s\""), 
-                                 (unsigned char*) l->data);
+       caption = g_strdup_printf(_("\"%s\" unknown in %s"), 
+                                 (unsigned char*) l->data, 
+                                 gtkpspell->gtkpspeller->dictionary->dictname);
        item = gtk_menu_item_new_with_label(caption);
        gtk_widget_show(item);
        gtk_menu_append(GTK_MENU(menu), item);
@@ -1748,6 +1797,19 @@ static GtkMenu *make_sug_menu(GtkPspell *gtkpspell)
        gtk_widget_add_accelerator(item, "activate", accel, GDK_R, 0,
                                   GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
 
+       if (gtkpspell->use_alternate && gtkpspell->alternate_speller) {
+               caption = g_strdup_printf(_("Check with %s"), 
+                       gtkpspell->alternate_speller->dictionary->dictname);
+               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),
+                               gtkpspell);
+               gtk_widget_add_accelerator(item, "activate", accel, GDK_X, 0,
+                                          GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
+       }
        item = gtk_menu_item_new();
         gtk_widget_show(item);
         gtk_menu_append(GTK_MENU(menu), item);
@@ -1838,7 +1900,19 @@ static void populate_submenu(GtkPspell *gtkpspell, GtkWidget *menu)
        item = gtk_menu_item_new();
         gtk_widget_show(item);
         gtk_menu_append(GTK_MENU(menu), item);
-               
+
+       if (gtkpspell->use_alternate && gtkpspell->alternate_speller) {
+               dictname = g_strdup_printf(_("Use alternate (%s)"), 
+                               gtkpspell->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),
+                                  gtkpspell);
+               gtk_widget_show(item);
+               gtk_menu_append(GTK_MENU(menu), item);
+       }
+
        item = gtk_check_menu_item_new_with_label(_("Fast Mode"));
        if (ispell || gtkpspell->gtkpspeller->sug_mode == PSPELL_FASTMODE)
                gtk_widget_set_sensitive(GTK_WIDGET(item),FALSE);
@@ -1956,7 +2030,7 @@ static GtkMenu *make_config_menu(GtkPspell *gtkpspell)
                gtkpspell->popup_config_menu = gtk_menu_new();
 
        debug_print("Pspell: creating/using popup_config_menu %0x\n", 
-                       gtkpspell->popup_config_menu);
+                       (guint) gtkpspell->popup_config_menu);
        populate_submenu(gtkpspell, gtkpspell->popup_config_menu);
 
         return GTK_MENU(gtkpspell->popup_config_menu);
@@ -1969,7 +2043,7 @@ void gtkpspell_populate_submenu(GtkPspell *gtkpspell, GtkWidget *menuitem)
        menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
        
        debug_print("Pspell: using config menu %0x\n", 
-                       gtkpspell->popup_config_menu);
+                       (guint) gtkpspell->popup_config_menu);
        populate_submenu(gtkpspell, menu);
        
        gtkpspell->config_menu = menu;
@@ -2037,6 +2111,13 @@ static void change_dict_cb(GtkWidget *w, GtkPspell *gtkpspell)
        dict = g_new0(Dictionary, 1);
        dict->fullname = g_strdup(fullname);
        dict->encoding = g_strdup(gtkpspell->gtkpspeller->dictionary->encoding);
+
+       if (gtkpspell->use_alternate && gtkpspell->alternate_speller &&
+           dict == gtkpspell->alternate_speller->dictionary) {
+               use_alternate_dict(gtkpspell);
+               dictionary_delete(dict);
+               return;
+       }
        
        gtkpspeller = gtkpspeller_new(dict);
 
@@ -2048,7 +2129,13 @@ static void change_dict_cb(GtkWidget *w, GtkPspell *gtkpspell)
                gtkpspell_alert_dialog(message); 
                g_free(message);
        } else {
-               gtkpspeller_delete(gtkpspell->gtkpspeller);
+               if (gtkpspell->use_alternate) {
+                       if (gtkpspell->alternate_speller)
+                               gtkpspeller_delete(gtkpspell->alternate_speller);
+                       gtkpspell->alternate_speller = gtkpspell->gtkpspeller;
+               } else
+                       gtkpspeller_delete(gtkpspell->gtkpspeller);
+
                gtkpspell->gtkpspeller = gtkpspeller;
                gtkpspell_set_sug_mode(gtkpspell, sug_mode);
        }
@@ -2060,6 +2147,13 @@ static void change_dict_cb(GtkWidget *w, GtkPspell *gtkpspell)
 
 }
 
+static void switch_to_alternate_cb(GtkWidget *w,
+                                  gpointer data)
+{
+       GtkPspell *gtkpspell = (GtkPspell *) data;
+       use_alternate_dict(gtkpspell);
+}
+
 /******************************************************************************/
 /* Misc. helper functions */