soc.2008.finch: 901756ef: Forgot to commit this before.

queueram at soc.pidgin.im queueram at soc.pidgin.im
Sun Jul 6 17:46:12 EDT 2008


-----------------------------------------------------------------
Revision: 901756ef486a40308f2bf609ed9b9bf7ddd91c91
Ancestor: ae37157835a93112dda1fa3fed349dfaf4f59008
Author: queueram at soc.pidgin.im
Date: 2008-07-06T21:37:56
Branch: im.pidgin.soc.2008.finch
URL: http://d.pidgin.im/viewmtn/revision/info/901756ef486a40308f2bf609ed9b9bf7ddd91c91

Modified files:
        finch/libgnt/gntentry.c

ChangeLog: 

Forgot to commit this before.
This is the last optimization made to the current spell checking algorithm.

-------------- next part --------------
============================================================
--- finch/libgnt/gntentry.c	eac3670f83af1e7c897b4fed29d0e167f340892d
+++ finch/libgnt/gntentry.c	bed927603e6b2dc0719e1abfa6e0cc26e479c7dd
@@ -388,8 +388,13 @@ gnt_entry_draw(GntWidget *widget)
 		 * out here so the spellchecking isn't always performed for each word on
 		 * a gnt_entry_draw */
 		char *s, *e;
-		int miss = gnt_color_pair(GNT_COLOR_MISSPELL);
-		int missd = gnt_color_pair(GNT_COLOR_MISSPELL_D);
+		int miss_color;
+		int count;
+		int width;
+		if (focus)
+			miss_color = gnt_color_pair(GNT_COLOR_MISSPELL);
+		else
+			miss_color = gnt_color_pair(GNT_COLOR_MISSPELL_D);
 		/* only spell check if enabled and box isn't empty */
 		if (entry->spell->enable && (entry->start != entry->end)) {
 			wmove(widget->window, 0, 0);
@@ -405,11 +410,10 @@ gnt_entry_draw(GntWidget *widget)
 			}
 			e = get_end_of_word(s, entry->end);
 
-			/* TODO: pick better attribute for misspelled words */
 			if (!check_word(entry, s, e)) {
-				wattron(widget->window, (focus ? miss : missd));
+				wattron(widget->window, miss_color);
 			} else {
-				wattroff(widget->window, (focus ? miss : missd));
+				wattroff(widget->window, miss_color);
 			}
 			/* first word might be special case if scroll is in middle of word */
 			if (s < entry->scroll) {
@@ -418,10 +422,13 @@ gnt_entry_draw(GntWidget *widget)
 				waddnstr(widget->window, s, e - s + 1);
 			}
 
+			gnt_widget_get_size(GNT_WIDGET(entry), &width, NULL);
+			count = 0;
 			s = g_utf8_find_next_char(e, entry->end);
-			while(s) {
+			while(s && count < width) {
+				count++;
 				/* print the whitespace and punctuation characters */
-				wattroff(widget->window, (focus ? miss : missd));
+				wattroff(widget->window, miss_color);
 				e = get_beginning_of_next_word(s, entry->end);
 				if (!e && s < entry->end) {
 					/* the end is all non-letter characters */
@@ -433,11 +440,10 @@ gnt_entry_draw(GntWidget *widget)
 					s = e;
 					e = get_end_of_word(s, entry->end);
 
-					/* TODO: pick better attribute for misspelled words */
 					if (!check_word(entry, s, e)) {
-						wattron(widget->window, (focus ? miss : missd));
+						wattron(widget->window, miss_color);
 					} else {
-						wattroff(widget->window, (focus ? miss : missd));
+						wattroff(widget->window, miss_color);
 					}
 					waddnstr(widget->window, s, e - s + 1);
 					s = g_utf8_find_next_char(e, entry->end);
@@ -446,10 +452,10 @@ gnt_entry_draw(GntWidget *widget)
 				}
 			}
 		} else {
-			wattroff(widget->window, (focus ? miss : missd));
+			wattroff(widget->window, miss_color);
 			mvwprintw(widget->window, 0, 0, "%s", entry->scroll);
 		}
-		wattroff(widget->window, (focus ? miss : missd));
+		wattroff(widget->window, miss_color);
 #else
 		mvwprintw(widget->window, 0, 0, "%s", entry->scroll);
 #endif
@@ -1130,7 +1136,7 @@ set_spell_language(GntEntrySpell *spell,
 static void
 set_spell_language(GntEntrySpell *spell, const char *lang)
 {
-    const char *err;
+	const char *err;
 
 	if (spell->broker) {
 		if (spell->dict)
@@ -1298,7 +1304,7 @@ create_spell_suggestions_menu(GntMenu *m
 	GntMenuItem *item;
 	GntWidget *sub;
 	char **suggs;
-    size_t n_suggs = 0;
+	size_t n_suggs = 0;
 	int i;
 
 	if (entry->spell && entry->spell->broker) {
@@ -1323,7 +1329,7 @@ draw_context_menu(GntEntry *entry)
 draw_context_menu(GntEntry *entry)
 {
 	GntWidget *context = NULL;
-	int x, y, width;
+	int x, y;
 	char *start, *end;
 
 	if (entry->spell->context)
@@ -1351,7 +1357,6 @@ draw_context_menu(GntEntry *entry)
 
 	/* Set the position for the popup */
 	gnt_widget_get_position(GNT_WIDGET(entry), &x, &y);
-	gnt_widget_get_size(GNT_WIDGET(entry), &width, NULL);
 
 	x += entry->cursor - entry->scroll;
 	y += 1;


More information about the Commits mailing list