? massif.29182.ps ? massif.29182.txt ? docs/gtkspell-overrides.txt ? examples/massif.28982.aux ? examples/massif.28982.ps ? examples/massif.28990.aux ? examples/massif.28990.ps Index: gtkspell/gtkspell.c =================================================================== RCS file: /cvsroot/gtkspell/gtkspell3/gtkspell/gtkspell.c,v retrieving revision 1.13 diff -u -p -r1.13 gtkspell.c --- gtkspell/gtkspell.c 22 May 2005 16:08:49 -0000 1.13 +++ gtkspell/gtkspell.c 8 Oct 2005 17:36:42 -0000 @@ -27,11 +27,13 @@ #include #include #include +#include #include "gtkspell.h" #include "gtkspell-iso-codes.h" #define GTKSPELL_MISSPELLED_TAG "gtkspell-misspelled" +#define GTKSPELL_OBJECT_KEY "gtkspell" /* * 0 == off @@ -40,30 +42,177 @@ */ const int debug = 1; +static void gtkspell_init(GtkSpell *spell); +static void gtkspell_class_init(GtkSpellClass *klass); +static void gtkspell_dispose(GObject *object); +static void gtkspell_finalize(GObject *object); + +static EnchantBroker *broker; +static GSList *dict_list; +static GHashTable *dict_hash; + struct _GtkSpell { + GObject parent; + GtkTextView *view; GtkTextTag *tag_highlight; GtkTextMark *mark_insert_start; GtkTextMark *mark_insert_end; gboolean deferred_check; - EnchantBroker *broker; - GSList *dict_list; - GHashTable *dict_hash; GtkTextMark *mark_click; + + gboolean dispose_has_run; }; -static void gtkspell_free(GtkSpell *spell); +struct _GtkSpellClass { + GObjectClass parent; -#define GTKSPELL_OBJECT_KEY "gtkspell" +}; + +static GObjectClass *parent_class = NULL; + +/* +enum { + ACTIVATE_LANGUAGE, + DEACTIVATE_LANGUAGE, + LAST_SIGNAL +}; + +static gint gtkspell_signals[LAST_SIGNAL] = {0}; +*/ GQuark -gtkspell_error_quark(void) { +gtkspell_error_quark() { static GQuark q = 0; if (q == 0) q = g_quark_from_static_string("gtkspell-error-quark"); return q; } +GType +gtkspell_get_type() { + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof(GtkSpellClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gtkspell_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(GtkSpell), + 0, /* n_preallocs */ + (GInstanceInitFunc) gtkspell_init + }; + + type = g_type_register_static(G_TYPE_OBJECT, "GtkSpell", &info, (GTypeFlags)0); + } + + return type; +} + +static void +gtkspell_class_init(GtkSpellClass *klass) { + GObjectClass *object_class; + + if (debug) + g_print("gtkspell_class_init\n"); + + parent_class = G_OBJECT_CLASS(g_type_class_peek_parent(klass)); + object_class = G_OBJECT_CLASS(klass); + + object_class->dispose = gtkspell_dispose; + object_class->finalize = gtkspell_finalize; +} + +/* +static void +gtkspell_class_finalize(GtkSpellClass *klass) { + + if (debug) + g_print("gtkspell_class_finalize\n"); + + if (klass->broker) { + EnchantDict *dict; + GSList *li; + + for (li = klass->dict_list; li != NULL; li = g_slist_next(li)) { + dict = (EnchantDict *)li->data; + enchant_broker_free_dict (klass->broker, dict); + } + + enchant_broker_free (klass->broker); + } + + if (klass->dict_list) + g_slist_free(klass->dict_list); + + if (klass->dict_hash) + g_hash_table_destroy(klass->dict_hash); + +} +*/ + +static void +gtkspell_init(GtkSpell *spell) { + + if (debug) + g_print("gtkspell_init\n"); + + spell->dispose_has_run = FALSE; +} + +static void +gtkspell_dispose(GObject *object) { + GtkTextBuffer *buffer; + GtkTextTagTable *table; + GtkTextIter start, end; + GtkSpell *spell = (GtkSpell *)object; + + if (debug) + g_print("gtkspell_dispose\n"); + + if (spell->dispose_has_run) + return; + + spell->dispose_has_run = TRUE; + + buffer = gtk_text_view_get_buffer(spell->view); + table = gtk_text_buffer_get_tag_table(buffer); + + gtk_text_buffer_get_bounds(buffer, &start, &end); + gtk_text_buffer_remove_tag(buffer, spell->tag_highlight, &start, &end); + + gtk_text_buffer_delete_mark(buffer, spell->mark_insert_start); + gtk_text_buffer_delete_mark(buffer, spell->mark_insert_end); + gtk_text_buffer_delete_mark(buffer, spell->mark_click); + + + g_signal_handlers_disconnect_matched(spell->view, + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); + + g_signal_handlers_disconnect_matched(buffer, + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); + + G_OBJECT_CLASS(parent_class)->dispose(object); +} + +static void +gtkspell_finalize(GObject *obj) { + GtkSpell *spell = (GtkSpell *)obj; + + if (debug) + g_print("gtkspell_finalize\n"); + + G_OBJECT_CLASS(parent_class)->finalize(obj); +} + + #if 0 static gboolean gtkspell_text_iter_forward_word_end(GtkTextIter *i) { @@ -123,7 +272,7 @@ check_word(GtkSpell *spell, GtkTextBuffe EnchantDict *dict; gboolean misspelled; - if (!spell->dict_list) + if (!dict_list) return; text = gtk_text_buffer_get_text(buffer, start, end, FALSE); @@ -138,7 +287,7 @@ check_word(GtkSpell *spell, GtkTextBuffe } misspelled = TRUE; - for (li = spell->dict_list; li != NULL; li = g_slist_next(li)) { + for (li = dict_list; li != NULL; li = g_slist_next(li)) { dict = (EnchantDict *)li->data; if (enchant_dict_check(dict, text, strlen(text)) == 0) { misspelled = FALSE; @@ -332,7 +481,7 @@ add_to_dictionary(GtkWidget *menuitem, G GtkTextIter start, end; gchar *word; - if (!spell->dict_list) + if (!dict_list) return; buffer = gtk_text_view_get_buffer(spell->view); @@ -357,7 +506,7 @@ ignore_all(GtkWidget *menuitem, GtkSpell GtkTextIter start, end; gchar *word; - if (!spell->dict_list) + if (!dict_list) return; buffer = gtk_text_view_get_buffer(spell->view); @@ -365,7 +514,7 @@ ignore_all(GtkWidget *menuitem, GtkSpell get_word_extents_from_mark(buffer, &start, &end, spell->mark_click); word = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); - for (li = spell->dict_list; li != NULL; li = g_slist_next(li)) { + for (li = dict_list; li != NULL; li = g_slist_next(li)) { dict = (EnchantDict *)li->data; enchant_dict_add_to_session(dict, word, strlen(word)); } @@ -382,7 +531,7 @@ replace_word(GtkWidget *menuitem, GtkSpe gchar *oldword; const gchar *newword; - if (!spell->dict_list) + if (!dict_list) return; buffer = gtk_text_view_get_buffer(spell->view); @@ -485,19 +634,19 @@ build_spelling_menu(GtkSpell *spell, con topmenu = gtk_menu_new(); - if (!spell->dict_list) + if (!dict_list) return topmenu; /* Suggestions */ - if (g_slist_length(spell->dict_list) == 1) { - dict = (EnchantDict *)(spell->dict_list->data); + if (g_slist_length(dict_list) == 1) { + dict = (EnchantDict *)(dict_list->data); build_suggestion_menu(spell, topmenu, dict, word); } else { GSList *li; GtkWidget *menu; gchar *lang, *lang_name; - for (li = spell->dict_list; li != NULL; li = g_slist_next(li)) { + for (li = dict_list; li != NULL; li = g_slist_next(li)) { dict = (EnchantDict *)li->data; lang = get_lang_from_dict(dict); lang_name = gtkspell_iso_codes_lookup_name_for_code(lang); @@ -525,8 +674,8 @@ build_spelling_menu(GtkSpell *spell, con gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU)); - if (g_slist_length(spell->dict_list) == 1) { - dict = (EnchantDict *)(spell->dict_list->data); + if (g_slist_length(dict_list) == 1) { + dict = (EnchantDict *)(dict_list->data); gtk_object_set_data(GTK_OBJECT(mi), "gtkspell-dict", dict); g_signal_connect(G_OBJECT(mi), "activate", @@ -539,7 +688,7 @@ build_spelling_menu(GtkSpell *spell, con menu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(mi), menu); - for (li = spell->dict_list; li != NULL; li = g_slist_next(li)) { + for (li = dict_list; li != NULL; li = g_slist_next(li)) { dict = (EnchantDict *)li->data; lang = get_lang_from_dict(dict); lang_name = gtkspell_iso_codes_lookup_name_for_code(lang); @@ -663,19 +812,21 @@ static gboolean gtkspell_activate_language_internal(GtkSpell *spell, const gchar *lang, GError **error) { EnchantDict *dict; - if (!spell->broker) - spell->broker = enchant_broker_init(); + if (!broker) { + broker = enchant_broker_init(); + dict_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + } if (debug) g_print("activate %s\n", lang); - if (g_hash_table_lookup(spell->dict_hash, lang)) + if (g_hash_table_lookup(dict_hash, lang)) return TRUE; if (debug) g_print("request dictionary for %s\n", lang); - dict = enchant_broker_request_dict (spell->broker, lang); + dict = enchant_broker_request_dict (broker, lang); if (!dict) { g_set_error(error, GTKSPELL_ERROR, GTKSPELL_ERROR_BACKEND, @@ -684,8 +835,8 @@ gtkspell_activate_language_internal(GtkS return FALSE; } - spell->dict_list = g_slist_append(spell->dict_list, (gpointer)dict); - g_hash_table_insert(spell->dict_hash, get_lang_from_dict(dict), (gpointer)dict); + dict_list = g_slist_append(dict_list, (gpointer)dict); + g_hash_table_insert(dict_hash, get_lang_from_dict(dict), (gpointer)dict); return TRUE; } @@ -779,7 +930,7 @@ gtkspell_activate_language(GtkSpell *spe void gtkspell_deactivate_language(GtkSpell *spell, const gchar *lang) { - if (!spell->dict_list) + if (!dict_list) return; if (lang) { @@ -788,14 +939,14 @@ gtkspell_deactivate_language(GtkSpell *s if (debug) g_print("deactivate %s\n", lang); - dict = g_hash_table_lookup(spell->dict_hash, lang); + dict = g_hash_table_lookup(dict_hash, lang); if (!dict) return; - enchant_broker_free_dict(spell->broker, dict); - spell->dict_list = g_slist_remove(spell->dict_list, dict); - g_hash_table_remove (spell->dict_hash, lang); + enchant_broker_free_dict(broker, dict); + dict_list = g_slist_remove(dict_list, dict); + g_hash_table_remove (dict_hash, lang); } else { /* deactivate all */ @@ -805,15 +956,15 @@ gtkspell_deactivate_language(GtkSpell *s if (debug) g_print("deactivate all\n"); - for (li = spell->dict_list; li != NULL; li = g_slist_next(li)) { + for (li = dict_list; li != NULL; li = g_slist_next(li)) { dict = (EnchantDict *)li->data; - enchant_broker_free_dict(spell->broker, dict); + enchant_broker_free_dict(broker, dict); } - g_slist_free(spell->dict_list); - g_hash_table_destroy(spell->dict_hash); - spell->dict_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); - spell->dict_list = NULL; + g_slist_free(dict_list); + g_hash_table_destroy(dict_hash); + dict_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + dict_list = NULL; } gtkspell_recheck_all(spell); @@ -832,7 +983,7 @@ gtkspell_recheck_all(GtkSpell *spell) { GtkTextIter start, end; if (debug) - g_print("recheck all (%d dicts)\n", g_slist_length(spell->dict_list)); + g_print("recheck all (%d dicts)\n", g_slist_length(dict_list)); buffer = gtk_text_view_get_buffer(spell->view); @@ -866,9 +1017,10 @@ gtkspell_new_attach(GtkTextView *view, c g_assert(spell == NULL); /* attach to the widget */ - spell = g_new0(GtkSpell, 1); + //spell = g_new0(GtkSpell, 1); + spell = GTKSPELL(g_object_new(GTKSPELL_TYPE, NULL)); + spell->view = view; - spell->dict_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); activate_default_languages(spell); @@ -945,52 +1097,11 @@ gtkspell_new_attach(GtkTextView *view, c static void gtkspell_free(GtkSpell *spell) { - GtkTextBuffer *buffer; - GtkTextTagTable *table; - GtkTextIter start, end; - GSList *li; - - if (debug) - g_print("gtkspell_free\n"); - - buffer = gtk_text_view_get_buffer(spell->view); - table = gtk_text_buffer_get_tag_table(buffer); - - gtk_text_buffer_get_bounds(buffer, &start, &end); - gtk_text_buffer_remove_tag(buffer, spell->tag_highlight, &start, &end); - - gtk_text_buffer_delete_mark(buffer, spell->mark_insert_start); - gtk_text_buffer_delete_mark(buffer, spell->mark_insert_end); - gtk_text_buffer_delete_mark(buffer, spell->mark_click); - - if (spell->broker) { - EnchantDict *dict; - - for (li = spell->dict_list; li != NULL; li = g_slist_next(li)) { - dict = (EnchantDict *)li->data; - enchant_broker_free_dict (spell->broker, dict); - } - - enchant_broker_free (spell->broker); - } - - if (spell->dict_list) - g_slist_free(spell->dict_list); - - if (spell->dict_hash) - g_hash_table_destroy(spell->dict_hash); - g_signal_handlers_disconnect_matched(spell->view, - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); - - g_signal_handlers_disconnect_matched(buffer, - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); + if (spell->dispose_has_run) + return; - g_free(spell); + g_object_unref(G_OBJECT(spell)); } /** @@ -1050,10 +1161,10 @@ GSList * gtkspell_get_languages(GtkSpell *spell) { GSList *langs = NULL; - if (!spell->broker) + if (!broker) return NULL; - enchant_broker_list_dicts(spell->broker, dict_describe_cb, &langs); + enchant_broker_list_dicts(broker, dict_describe_cb, &langs); return langs; } @@ -1087,6 +1198,6 @@ gtkspell_get_language_name(GtkSpell *spe gboolean gtkspell_language_is_active(GtkSpell *spell, const gchar *lang) { - return (g_hash_table_lookup(spell->dict_hash, lang) != NULL); + return (g_hash_table_lookup(dict_hash, lang) != NULL); } Index: gtkspell/gtkspell.h =================================================================== RCS file: /cvsroot/gtkspell/gtkspell3/gtkspell/gtkspell.h,v retrieving revision 1.7 diff -u -p -r1.7 gtkspell.h --- gtkspell/gtkspell.h 22 May 2005 14:12:22 -0000 1.7 +++ gtkspell/gtkspell.h 8 Oct 2005 17:36:42 -0000 @@ -24,16 +24,28 @@ #ifndef GTKSPELL_H #define GTKSPELL_H -#define GTKSPELL_ERROR gtkspell_error_quark() +G_BEGIN_DECLS + +#define GTKSPELL_TYPE (gtkspell_get_type ()) +#define GTKSPELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTKSPELL_TYPE, GtkSpell)) +#define GTKSPELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTKSPELL_TYPE, GtkSpellClass)) +#define GTKSPELL_IS_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTKSPELL_TYPE)) +#define GTKSPELL_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTKSPELL_TYPE)) +#define GTKSPELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTKSPELL_TYPE, GtkSpellClass)) + +typedef struct _GtkSpell GtkSpell; +typedef struct _GtkSpellClass GtkSpellClass; +#define GTKSPELL_ERROR gtkspell_error_quark() typedef enum { GTKSPELL_ERROR_BACKEND, } GtkSpellError; GQuark gtkspell_error_quark(); -typedef struct _GtkSpell GtkSpell; +GtkType gtkspell_get_type(void); +static void gtkspell_free(GtkSpell *spell); /* the idea is to have a GtkSpell object that is analagous to the * GtkTextBuffer-- it lives as an attribute of the GtkTextView but * it can be referred to directly. */ @@ -75,4 +87,6 @@ gboolean gtkspell_set_language(GtkSpell #endif /* GTKSPELL_DISABLE_DEPRECATED */ +G_END_DECLS + #endif /* GTKSPELL_H */