Privatized most of GtkAspell's structures
[claws.git] / src / gtk / gtkaspell.c
index efaf39535606e01abe3546576a71054d9c5f2a10..cde57ccdfd7940edf1577639ef346b1e127c66cc 100644 (file)
@@ -28,7 +28,7 @@
 #  include "config.h"
 #endif
 
-#if USE_ASPELL
+#ifdef USE_ASPELL
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <gtk/gtkmenuitem.h>
 #include <gdk/gdkkeysyms.h>
 
+#include <aspell.h>
+
 #include "intl.h"
 #include "gtkstext.h"
 #include "utils.h"
+
 #include "gtkaspell.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();                      \
        }
 
+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         use_alternate;
+
+       ContCheckFunc    continue_check; 
+
+       GtkWidget       *config_menu;
+       GtkWidget       *popup_config_menu;
+       GtkWidget       *sug_menu;
+       GtkWidget       *replace_entry;
+
+       gint             default_sug_mode;
+       gint             max_sug;
+       GList           *suggestions_list;
+
+       GtkSText        *gtktext;
+       GdkColor         highlight;
+};
+
+typedef AspellConfig GtkAspellConfig;
+
 /******************************************************************************/
 
-GtkAspellCheckers *gtkaspellcheckers;
+static GtkAspellCheckers *gtkaspellcheckers;
 
 /* Error message storage */
 static void gtkaspell_checkers_error_message   (gchar          *message);
@@ -191,25 +251,21 @@ GtkAspellConfig * gtkaspellconfig;
 
 /******************************************************************************/
 
-GtkAspellCheckers *gtkaspell_checkers_new(void)
+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",
@@ -229,7 +285,7 @@ GtkAspellCheckers *gtkaspell_checkers_delete(void)
 
        g_free(gtkaspellcheckers->error_message);
 
-       return NULL;
+       return;
 }
 
 static void gtkaspell_checkers_error_message (gchar *message)
@@ -245,6 +301,12 @@ static void gtkaspell_checkers_error_message (gchar *message)
                gtkaspellcheckers->error_message = message;
 }
 
+const char *gtkaspell_checkers_strerror(void)
+{
+       g_return_if_fail(gtkaspellcheckers);
+       return gtkaspellcheckers->error_message;
+}
+
 void gtkaspell_checkers_reset_error(void)
 {
        g_return_if_fail(gtkaspellcheckers);
@@ -1439,7 +1501,7 @@ 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;