fa1a5ab2c5d064f5e38103c44cc2c265aabe36ab
[claws.git] / src / gtk / gtkaspell.h
1 /*
2     Stuphead: (C) 2000,2001 Grigroy Bakunov, Sergey Pinaev
3  */
4 /* gtkaspell - a spell-checking addon for GtkText
5  * Copyright (c) 2001-2002 Melvin Hadasht
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 3 of the License, or (at your option) any later version.
11  * 
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 /*
22  * Adapted by the Claws Mail Team.
23  */
24
25 /*
26  *  Adapted for pspell (c) 2001-2002 Melvin Hadasht
27  *  Adapted for GNU/aspell (c) 2002 Melvin Hadasht
28  *
29  */
30
31 #ifndef __GTKENCHANT_H__
32 #define __GTKENCHANT_H__
33
34 #ifdef HAVE_CONFIG_H
35 #  include "config.h"
36 #include "claws-features.h"
37 #endif
38
39 #ifdef USE_ENCHANT
40
41 #include <gtk/gtk.h>
42 #include <enchant.h>
43
44 #define GTKASPELLWORDSIZE 1024
45
46 typedef struct _Dictionary {
47         gchar *fullname;
48         gchar *dictname;
49 } Dictionary;
50
51 typedef struct _GtkAspeller {
52         Dictionary      *dictionary;
53         EnchantBroker   *broker;
54         EnchantDict     *speller;
55 } GtkAspeller;
56
57 typedef void (*ContCheckFunc) (gpointer *gtkaspell);
58
59 struct _WidgetContext
60 {
61         void            (*set_position)(gpointer data, gint pos);
62         void            (*set_menu_pos)(GtkMenu *menu, gint *x, gint *y,
63                                 gboolean *push_in, gpointer user_data);
64         gboolean        (*find_misspelled)(gpointer data, gboolean forward);
65         gboolean        (*check_word)(gpointer data);
66         void            (*replace_word)(gpointer data, const gchar *newword);
67         gpointer        *data; 
68 };
69
70 typedef struct _WidgetContext WidgetContext;
71
72 struct _GtkAspell
73 {
74         GtkAspeller     *gtkaspeller;
75         GtkAspeller     *alternate_speller;
76         gchar            theword[GTKASPELLWORDSIZE];
77         gint             start_pos;
78         gint             end_pos;
79         gint             orig_pos;
80         gint             end_check_pos;
81         gboolean         misspelled;
82         gboolean         check_while_typing;
83         gboolean         recheck_when_changing_dict;
84         gboolean         use_alternate;
85         gboolean         use_both_dicts;
86
87         ContCheckFunc    continue_check; 
88
89         GtkWidget       *replace_entry;
90         GtkWidget       *parent_window;
91
92         gint             max_sug;
93         GList           *suggestions_list;
94
95         GtkTextView     *gtktext;
96         GdkColor         highlight;
97         GtkAccelGroup   *accel_group;
98         void            (*dict_changed_cb)(void *data);
99         void            (*menu_changed_cb)(void *data);
100         void            *menu_changed_data;
101         
102         WidgetContext   ctx;
103 };
104
105 typedef struct _GtkAspell GtkAspell;
106
107
108 void            gtkaspell_checkers_init         (void);
109
110 void            gtkaspell_checkers_quit         (void);
111
112 const char *    gtkaspell_checkers_strerror     (void);
113
114 void            gtkaspell_checkers_reset_error  (void);
115
116 GtkAspell*      gtkaspell_new                   (const gchar *dictionary, 
117                                                  const gchar *alt_dictionary, 
118                                                  const gchar *encoding,
119                                                  gint  misspelled_color,
120                                                  gboolean check_while_typing,
121                                                  gboolean recheck_when_changing_dict,
122                                                  gboolean use_alternate,  
123                                                  gboolean use_both_dicts,  
124                                                  GtkTextView *gtktext,
125                                                  GtkWindow *parent_win,
126                                                  void (*dict_changed_cd)(void *data), 
127                                                  void (*spell_menu_cb)(void *data),
128                                                  void *data);
129
130 void            gtkaspell_delete                (GtkAspell *gtkaspell); 
131
132
133 gboolean        gtkaspell_change_dict           (GtkAspell *gtkaspell,
134                                                  const gchar* dictionary,
135                                                          gboolean always_set_alt_dict);
136
137 gboolean        gtkaspell_change_alt_dict       (GtkAspell *gtkaspell,
138                                                  const gchar* alt_dictionary);
139 void            gtkaspell_use_alternate_dict    (GtkAspell *gtkaspell);
140
141 gboolean        gtkaspell_check_next_prev       (GtkAspell *gtkaspell,
142                                                  gboolean forward);
143 void            gtkaspell_check_forwards_go     (GtkAspell *gtkaspell);
144 void            gtkaspell_check_backwards       (GtkAspell *gtkaspell);
145
146 void            gtkaspell_check_all             (GtkAspell *gtkaspell);
147 void            gtkaspell_highlight_all         (GtkAspell *gtkaspell);
148
149 GtkWidget*      gtkaspell_dictionary_combo_new  (const gboolean refresh);
150
151 GtkTreeModel*   gtkaspell_dictionary_store_new  (void);
152 GtkTreeModel*   gtkaspell_dictionary_store_new_with_refresh
153                                                         (gboolean     refresh);
154
155 gchar*          gtkaspell_get_dictionary_menu_active_item
156                                                         (GtkComboBox *combo);
157 gint            gtkaspell_set_dictionary_menu_active_item
158                                                         (GtkComboBox *combo, 
159                                                          const gchar *dictionary);
160
161 GSList*         gtkaspell_make_config_menu              (GtkAspell      *gtkaspell);
162
163 gchar*          gtkaspell_get_default_dictionary        (GtkAspell *gtkaspell);
164
165 void            gtkaspell_make_context_menu             (GtkMenu        *menu,
166                                                          GtkAspell      *gtkaspell);
167
168 int             gtkaspell_misspelled_test               (GtkAspell *gtkaspell,
169                                                          char *word);
170 void            gtkaspell_dict_changed                  (GtkAspell *gtkaspell);
171 void            gtkaspell_context_set                   (GtkAspell *gtkaspell);
172 void            gtkaspell_free_suggestions_list         (GtkAspell *gtkaspell);
173 void            gtkaspell_block_check                   (GtkAspell *gtkaspell);
174 void            gtkaspell_unblock_check                 (GtkAspell *gtkaspell);
175
176
177 #endif /* USE_ENCHANT */
178 #endif /* __GTKENCHANT_H__ */