[evolution-patches] mail forward/backward search patch



Hi All,
	Pl. find the attached patch, the first one for
gtkhtml/src/htmlclueflow.c and second for  evolution/mail/mail-search.c
created against 1-4 branches. This fixes forward multibyte search in a
mail and also enables/fixes backward search for single byte/multibyte
mails.

Thanks for reviewing this one.

Regards,
Suresh
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.1814.2.13
diff -u -r1.1814.2.13 ChangeLog
--- ChangeLog	24 Sep 2003 17:10:02 -0000	1.1814.2.13
+++ ChangeLog	7 Oct 2003 17:25:35 -0000
@@ -1,3 +1,10 @@
+2003-10-07  Suresh Chandrasekharan <suresh chandrasekharan sun com>
+
+	* htmlclueflow.c (search_text): Fixes for supporting forward 
+	  multibyte search, backward search and backward multibyte search.
+
+	(search_set_info): -do-
+	 
 2003-07-31  Radek Doulik  <rodo ximian com>
 
 	* htmlengine-edit.c (html_engine_select_spell_word_editable): fix
Index: htmlclueflow.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlclueflow.c,v
retrieving revision 1.288
diff -u -r1.288 htmlclueflow.c
--- htmlclueflow.c	20 May 2003 18:25:14 -0000	1.288
+++ htmlclueflow.c	7 Oct 2003 17:25:35 -0000
@@ -1938,36 +1938,34 @@
 static void
 search_set_info (HTMLObject *cur, HTMLSearch *info, guchar *text, guint pos, guint len)
 {
-	guint text_len = 0;
+	guint text_len = (info->forward) ? 0 : strlen(text);
 	guint cur_len;
-
 	info->found_len = len;
 
 	if (info->found) {
 		g_list_free (info->found);
 		info->found = NULL;
 	}
-
 	while (cur) {
 		if (html_object_is_text (cur)) {
 			cur_len = strlen (HTML_TEXT (cur)->text);
-			if (text_len + cur_len > pos) {
+			if (info->forward ? text_len + cur_len > pos : text_len - cur_len <= pos ) {
 				if (!info->found) {
-					info->start_pos = g_utf8_pointer_to_offset (text + text_len,
+					info->start_pos = g_utf8_pointer_to_offset (text + text_len - (info->forward ? 0 : cur_len),
 										    text + pos);
 				}
 				info->found = g_list_append (info->found, cur);
-			}
-			text_len += cur_len;
-			if (text_len >= pos+info->found_len) {
-				info->stop_pos = info->start_pos + info->found_len;
+			} 
+			text_len += (info->forward ? cur_len : -cur_len);
+			if (info->forward ? (text_len >= pos + info->found_len ): text_len < pos + info->found_len) {
+				info->stop_pos = info->start_pos + info->text_len;
 				info->last     = HTML_OBJECT (cur);
 				return;
 			}
 		} else if (HTML_OBJECT_TYPE (cur) != HTML_TYPE_TEXTSLAVE) {
 			break;
 		}		
-		cur = cur->next;
+		cur = info->forward ? cur->next : cur->prev;
 	}
 
 	g_assert_not_reached ();
@@ -1984,10 +1982,10 @@
 	guint text_len;
 	guint eq_len;
 	gint  pos;
+	guint utf8_len; 
 	gboolean retval = FALSE;
 
 	/* printf ("search flow look for \"text\" %s\n", info->text); */
-
 	/* first get flow text_len */
 	text_len = 0;
 	while (cur) {
@@ -1999,16 +1997,14 @@
 		}
 		cur = (info->forward) ? cur->next : cur->prev;
 	}
-
+	
 	if (text_len > 0) {
-		par = g_new (gchar, text_len+1);
-		par [text_len] = 0;
+		par = g_new0 (gchar, text_len+1);
 
 		pp = (info->forward) ? par : par+text_len;
 
 		/* now fill par with text */
-		head = cur = (info->forward) ? *beg : end;
-		cur = *beg;
+		head = cur = *beg;
 		while (cur) {
 			if (html_object_is_text (cur)) {
 				if (!info->forward) {
@@ -2026,18 +2022,43 @@
 
 		/* set eq_len and pos counters */
 		eq_len = 0;
+		utf8_len = g_utf8_strlen (par, -1);
 		if (info->found) {
-			pos = info->start_pos + ((info->forward) ? 1 : -1);
+			if (info->forward) {
+				pos = info->start_pos + 1 ;
+				/* convert pos into offset within par */
+				pos = (gint)g_utf8_offset_to_pointer (par, pos) - (gint)par;
+			} else {
+				gint head_len = g_utf8_strlen (((HTMLText*)head)->text, -1);
+				/* New starting pos for backward search */
+				/* within the (head)->text		*/
+
+				pos = info->stop_pos - 2;
+
+				/* Absolute position within par */
+				if (pos >= 0)
+					pos = utf8_len - (head_len - pos);
+				
+				/* Get the byte offset with par, skip if */
+				/* par and (head)->text are the same     */
+
+				if (utf8_len >= head_len + 1)
+					pos = (gint) g_utf8_offset_to_pointer (par, pos < 0 ? utf8_len - head_len - 1 : pos) - (gint) par;
+
+				/* We have now the starting byte of the char */
+				/* from which the backward search starts, get*/
+				/* the end byte like follows		     */		
+				pos = (gint) g_utf8_next_char (par + pos) - (gint) par - 1;
+			}
 		} else {
-			pos = (info->forward) ? 0 : text_len - 1;
-		}
-
-		/* FIXME make shorter text instead */
-		if (!info->forward)
-			par [pos+1] = 0;
+			/* Last char in par, from which a new backward */
+			/* search  starts 			       */
 
+			gint tot_len = strlen (par);
+			pos = (info->forward) ? 0 : tot_len - 1;
+		}
 		if ((info->forward && pos < text_len)
-		    || (!info->forward && pos>0)) {
+		    || (!info->forward && pos>=0)) {
 			if (info->reb) {
 				/* regex search */
 				gint rv;
@@ -2085,17 +2106,18 @@
 				}
 #endif
 			} else {
+				gint info_len = strlen (info->text);
 				/* substring search - simple one - could be improved
 				   go thru par and look for info->text */
 				while (par [pos]) {
 					if (info->trans [(guchar) info->text
-							[(info->forward) ? eq_len : info->text_len - eq_len - 1]]
+							[(info->forward) ? eq_len : info_len - eq_len - 1]]
 					    == info->trans [par [pos]]) {
 						eq_len++;
-						if (eq_len == info->text_len) {
+						if (eq_len == info_len) {
 							search_set_info (head, info, par,
 									 pos - (info->forward ? eq_len-1 : 0),
-									 info->text_len);
+									 info_len);
 							retval=TRUE;
 							break;
 						}
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.2761.2.29
diff -u -r1.2761.2.29 ChangeLog
--- ChangeLog	2 Oct 2003 17:04:01 -0000	1.2761.2.29
+++ ChangeLog	7 Oct 2003 17:35:02 -0000
@@ -1,3 +1,8 @@
+2003-10-07  Suresh Chandrasekharan <suresh chandrasekharan sun com>
+
+	* mail-search.c: Enabled forward/backward search toggle
+	in 'Search in Message' dialog.
+
 2003-10-02  Suresh Chandrasekharan <suresh chandrasekharan sun com>
                                                                                 
         * mail-config-druid.c: Fix for 40917 "Backspace shouldn't highlight
Index: mail-search.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/Attic/mail-search.c,v
retrieving revision 1.28
diff -u -r1.28 mail-search.c
--- mail-search.c	3 Jun 2003 20:46:35 -0000	1.28
+++ mail-search.c	7 Oct 2003 17:35:02 -0000
@@ -174,14 +174,12 @@
 	
 }
 
-#if 0
 static void
 toggled_fwd_cb (GtkToggleButton *b, MailSearch *ms)
 {
 	ms->search_forward = gtk_toggle_button_get_active (b);
 	gtk_html_engine_search_set_forward (ms->mail->html, ms->search_forward);
 }
-#endif
 
 static void
 dialog_response_cb (GtkWidget *widget, int button, MailSearch *ms)
@@ -268,9 +266,7 @@
 	GtkWidget *entry;
 	GtkWidget *count_label;
 	GtkWidget *case_check;
-#if 0
 	GtkWidget *fwd_check;
-#endif
 	GtkWidget *button;
 	GtkWidget *msg_hbox;
 	GtkWidget *msg_frame;
@@ -318,9 +314,7 @@
 	gtk_container_set_border_width ((GtkContainer *) msg_frame, 6);
 	
 	case_check  = gtk_check_button_new_with_label (_("Case Sensitive"));
-#if 0
 	fwd_check   = gtk_check_button_new_with_label (_("Search Forward"));
-#endif
 	
 	ms->entry       = entry;
 	ms->count_label = count_label;
@@ -332,9 +326,7 @@
 	else
 		mail_search_set_subject (ms, NULL);
 	
-#if 0
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fwd_check),  ms->search_forward);
-#endif
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (case_check), ms->case_sensitive);
 	
   	gtk_box_pack_start (GTK_BOX (msg_hbox), GTK_WIDGET (msg_frame), TRUE, TRUE, 0);
@@ -356,9 +348,7 @@
 	 * be a 1.1 item.
 	 */
 	
-#if 0
 	gtk_box_pack_start (GTK_BOX (toggles_hbox), fwd_check,  FALSE, FALSE, 3);
-#endif
 	
 	gtk_box_pack_start (GTK_BOX (frame_vbox), find_hbox, FALSE, FALSE, 3);
   	gtk_box_pack_start (GTK_BOX (frame_vbox), matches_hbox, FALSE, FALSE, 3); 
@@ -380,9 +370,7 @@
 	/* Hook up signals */
 	
 	g_signal_connect (case_check, "toggled", G_CALLBACK (toggled_case_cb), ms);
-#if 0
 	g_signal_connect (fwd_check, "toggled", G_CALLBACK (toggled_fwd_cb), ms);
-#endif
 	g_signal_connect (ms, "response", G_CALLBACK (dialog_response_cb), ms);
 	
 	g_object_weak_ref ((GObject *) ms->mail, (GWeakNotify) gtk_widget_destroy, ms);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]