# HG changeset patch # User Rob Flynn # Date 957175928 0 # Node ID 610b7ffc4821875d0fc03debde8e2c187bc7cb58 # Parent 5531861bf3f587a6a0efe35e150164cd952c8f70 [gaim-migrate @ 216] Yeah, I ripped off torrey's spell checking code and made it work with GAIM :) committer: Tailor Script diff -r 5531861bf3f5 -r 610b7ffc4821 ChangeLog --- a/ChangeLog Mon May 01 00:43:23 2000 +0000 +++ b/ChangeLog Mon May 01 10:12:08 2000 +0000 @@ -5,6 +5,8 @@ * Some plugins built/installed by default * Option to automagically check for new releases * Ability to receive files (one-way file transfer) + * In-line spell checker (thanks to Torrey Searle of the + Everybuddy Devel team for this one) version 0.9.14: * Numerous Fixes by G. Sumner Hayes (buffer over flow patches, diff -r 5531861bf3f5 -r 610b7ffc4821 doc/CREDITS --- a/doc/CREDITS Mon May 01 00:43:23 2000 +0000 +++ b/doc/CREDITS Mon May 01 10:12:08 2000 +0000 @@ -12,6 +12,9 @@ Other Contributors: +Thanks to Torrey Searle for the spell checking code that +accompanies the gtk_text box :) + ** LOGO DESIGNED BY: Naru Sundar ** Peter Teichiman diff -r 5531861bf3f5 -r 610b7ffc4821 src/conversation.c --- a/src/conversation.c Mon May 01 00:43:23 2000 +0000 +++ b/src/conversation.c Mon May 01 10:12:08 2000 +0000 @@ -645,6 +645,7 @@ void check_everything(GtkWidget *entry) { struct conversation *c; + c = (struct conversation *)gtk_object_get_user_data(GTK_OBJECT(entry)); if (!c) return; if (invert_tags(entry, "", "", 0)) @@ -799,6 +800,28 @@ +static void check_spelling( GtkEditable * editable, gchar * new_text, + gint length, gint * position, + gpointer data ) +{ + gtk_signal_handler_block_by_func(GTK_OBJECT(editable), + GTK_SIGNAL_FUNC(check_spelling), + data); + //gtk_editable_insert_text( editable, new_text, length, position ); + gtk_text_set_point(GTK_TEXT(editable), *position); + gtk_text_insert(GTK_TEXT(editable), NULL, &(GTK_WIDGET(editable)->style->fg[0]), + NULL, new_text, length ); + if(isspace(new_text[0])) + { + gtk_text_freeze(GTK_TEXT(editable)); + spell_check(GTK_WIDGET(editable)); + gtk_text_thaw(GTK_TEXT(editable)); + } + gtk_signal_handler_unblock_by_func(GTK_OBJECT(editable), + GTK_SIGNAL_FUNC(check_spelling), + data); + gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert-text"); +} void show_conv(struct conversation *c) @@ -1067,6 +1090,7 @@ gtk_window_set_focus(GTK_WINDOW(win),entry); gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(delete_event_convo), c); + gtk_signal_connect(GTK_OBJECT(entry), "insert-text", GTK_SIGNAL_FUNC(check_spelling), entry); gtk_signal_connect(GTK_OBJECT(entry), "key_press_event", GTK_SIGNAL_FUNC(entry_key_pressed), entry); gtk_widget_show(win); diff -r 5531861bf3f5 -r 610b7ffc4821 src/gaim.h --- a/src/gaim.h Mon May 01 00:43:23 2000 +0000 +++ b/src/gaim.h Mon May 01 10:12:08 2000 +0000 @@ -332,7 +332,7 @@ #define TYPE_SIGNOFF 4 #define TYPE_KEEPALIVE 5 -#define REVISION "gaim:$Revision: 208 $" +#define REVISION "gaim:$Revision: 216 $" #define FLAPON "FLAPON\r\n\r\n" #define ROAST "Tic/Toc" @@ -401,6 +401,7 @@ #define OPT_GEN_SAVED_WINDOWS 0x00001000 #define OPT_GEN_DISCARD_WHEN_AWAY 0x00002000 #define OPT_GEN_CHECK_VERSIONS 0x00004000 +#define OPT_GEN_CHECK_SPELLING 0x00008000 extern int display_options; #define OPT_DISP_SHOW_TIME 0x00000001 @@ -480,6 +481,7 @@ extern struct aim_user *find_user(const char *); extern char *full_date(); extern void check_gaim_versions(); +extern void spell_check(GtkWidget *); /* Functions in server.c */ /* input to serv */ diff -r 5531861bf3f5 -r 610b7ffc4821 src/prefs.c --- a/src/prefs.c Mon May 01 00:43:23 2000 +0000 +++ b/src/prefs.c Mon May 01 10:12:08 2000 +0000 @@ -385,6 +385,7 @@ gaim_button("Save some window size/positions", &general_options, OPT_GEN_SAVED_WINDOWS, genbox); gaim_button("Ignore new conversations when away", &general_options, OPT_GEN_DISCARD_WHEN_AWAY, genbox); gaim_button("Automagically check for new releases", &general_options, OPT_GEN_CHECK_VERSIONS, genbox); + gaim_button("Automagically highlight misspelled words", &general_options, OPT_GEN_CHECK_SPELLING, genbox); if (!dw && (general_options & OPT_GEN_DEBUG)) general_options = general_options ^ OPT_GEN_DEBUG; debugbutton = gaim_button("Enable debug mode", &general_options, OPT_GEN_DEBUG, genbox); diff -r 5531861bf3f5 -r 610b7ffc4821 src/util.c --- a/src/util.c Mon May 01 00:43:23 2000 +0000 +++ b/src/util.c Mon May 01 10:12:08 2000 +0000 @@ -745,3 +745,79 @@ } +/* + +This function was taken from EveryBuddy and was written by +Torrey Searle. tsearle@valhalla.marko.net + +http://www.everybuddy.com + +*/ + +void spell_check(GtkWidget * text) +{ + int start = 0; + int end = 0; + int length = gtk_text_get_length(GTK_TEXT(text)); + static GdkColor * color = NULL; + int ignore = 0; + int point = gtk_editable_get_position(GTK_EDITABLE(text)); + + GString * string; + + if( color == NULL ) + { + GdkColormap * gc = gtk_widget_get_colormap( text ); + color = g_new0(GdkColor, 1); + color->red = 255 * 256; + gdk_colormap_alloc_color(gc, color, FALSE, TRUE); + } + + + + end = point-1; + for( start = end-1; start >= 0; start-- ) + { + if((isspace(GTK_TEXT_INDEX(GTK_TEXT(text), start)) || start == 0) + && !ignore) + { + char * word; + FILE * file; + char buff[1024]; + word = gtk_editable_get_chars( GTK_EDITABLE(text), start, end ); + g_snprintf(buff, 1024, "echo \"%s\" | ispell -l", word ); + file = popen(buff, "r"); + + buff[0] = 0; + fgets(buff, 255, file); + + if(strlen(buff) > 0 ) + { + string = g_string_new(word); + gtk_text_set_point(GTK_TEXT(text), end); + gtk_text_backward_delete(GTK_TEXT(text), end-start); + gtk_text_insert( GTK_TEXT(text), NULL, color, NULL, + string->str, string->len ); + g_string_free( string, TRUE ); + } + else + { + string = g_string_new(word); + gtk_text_set_point(GTK_TEXT(text), end); + gtk_text_backward_delete(GTK_TEXT(text), end-start); + gtk_text_insert( GTK_TEXT(text), NULL, &(text->style->fg[0]), NULL, + string->str, string->len ); + g_string_free( string, TRUE ); + } + pclose( file); + break; + } + else if(!isalpha(GTK_TEXT_INDEX(GTK_TEXT(text), start))) + { + ignore = 1; + } + } + gtk_text_set_point(GTK_TEXT(text), point); + +} +