diff src/gtkimhtml.c @ 9924:872c4d8c1192

[gaim-migrate @ 10816] Sam S. added back support for rendering <strike> Before anyone gets too excited and decides to add back sup, sub, and pre, I'd like to recode some stuff in imhtml and make it easier and cleaner to add tags, especially simple boolean tags like strike. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Tue, 31 Aug 2004 20:10:21 +0000
parents 650ea0a0d55e
children f1f239fa8973
line wrap: on
line diff
--- a/src/gtkimhtml.c	Tue Aug 31 18:28:35 2004 +0000
+++ b/src/gtkimhtml.c	Tue Aug 31 20:10:21 2004 +0000
@@ -1065,7 +1065,7 @@
 
 	/* These tags will be used often and can be reused--we create them on init and then apply them by name
 	 * other tags (color, size, face, etc.) will have to be created and applied dynamically
-	 * Note that even though we created STRIKE, SUB, SUP, and PRE tags here, we don't really
+	 * Note that even though we created SUB, SUP, and PRE tags here, we don't really
 	 * apply them anywhere yet. */
 	gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL);
 	gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL);
@@ -2102,14 +2102,20 @@
 					break;
 				case 13:	/* S */
 				case 14:	/* STRIKE */
-					/* FIXME: reimplement this */
+					gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
+					ws[0] = '\0'; wpos = 0;
+					if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE))
+						gtk_imhtml_toggle_strike(imhtml);
 					strike++;
 					break;
 				case 15:	/* /S */
 				case 16:	/* /STRIKE */
-					/* FIXME: reimplement this */
+					gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
+					ws[0] = '\0'; wpos = 0;
 					if (strike)
 						strike--;
+					if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE) && !imhtml->wbfo)
+						gtk_imhtml_toggle_strike(imhtml);
 					break;
 				case 17:	/* SUB */
 					/* FIXME: reimpliment this */
@@ -3297,6 +3303,11 @@
 	else
 		gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end);
 
+	if (imhtml->edit.strike)
+		gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, end);
+	else
+		gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, end);
+
 	if (imhtml->edit.forecolor) {
 		remove_font_forecolor(imhtml, &start, end, TRUE);
 		gtk_text_buffer_apply_tag(imhtml->text_buffer,
@@ -3446,7 +3457,7 @@
 	if (!gtk_text_buffer_get_char_count(buffer))
 		return;
 
-	imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = FALSE;
+	imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = imhtml->edit.strike = FALSE;
 	if (imhtml->edit.forecolor)
 		g_free(imhtml->edit.forecolor);
 	imhtml->edit.forecolor = NULL;
@@ -3477,6 +3488,8 @@
 				imhtml->edit.italic = TRUE;
 			if (strcmp(tag->name, "UNDERLINE") == 0)
 				imhtml->edit.underline = TRUE;
+			if (strcmp(tag->name, "STRIKE") == 0)
+				imhtml->edit.strike = TRUE;
 			if (strncmp(tag->name, "FORECOLOR ", 10) == 0)
 				imhtml->edit.forecolor = g_strdup(&(tag->name)[10]);
 			if (strncmp(tag->name, "BACKCOLOR ", 10) == 0)
@@ -3572,6 +3585,32 @@
 	return imhtml->edit.underline != FALSE;
 }
 
+gboolean gtk_imhtml_toggle_strike(GtkIMHtml *imhtml)
+{
+	GObject *object;
+	GtkTextIter start, end;
+
+	imhtml->edit.strike = !imhtml->edit.strike;
+
+	if (imhtml->wbfo) {
+		gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
+		if (imhtml->edit.strike)
+			gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
+		else
+			gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
+	} else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
+		if (imhtml->edit.strike)
+			gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
+		else
+			gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
+	}
+	object = g_object_ref(G_OBJECT(imhtml));
+	g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_STRIKE);
+	g_object_unref(object);
+
+	return imhtml->edit.strike != FALSE;
+}
+
 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size)
 {
 	GObject *object;
@@ -3930,6 +3969,8 @@
 		return "<i>";
 	} else if (strcmp(name, "UNDERLINE") == 0) {
 		return "<u>";
+	} else if (strcmp(name, "STRIKE") == 0) {
+		return "<s>";
 	} else if (strncmp(name, "LINK ", 5) == 0) {
 		char *tmp = g_object_get_data(G_OBJECT(tag), "link_url");
 		if (tmp) {
@@ -3969,6 +4010,8 @@
 		return "</i>";
 	} else if (strcmp(name, "UNDERLINE") == 0) {
 		return "</u>";
+	} else if (strcmp(name, "STRIKE") == 0) {
+		return "</s>";
 	} else if (strncmp(name, "LINK ", 5) == 0) {
 		return "</a>";
 	} else if (strncmp(name, "FORECOLOR ", 10) == 0) {
@@ -4115,6 +4158,9 @@
 	if (imhtml->edit.underline)
 		gtk_imhtml_toggle_underline(imhtml);
 
+	if (imhtml->edit.strike)
+		gtk_imhtml_toggle_strike(imhtml);
+
 	if (imhtml->edit.forecolor)
 		gtk_imhtml_toggle_forecolor(imhtml, NULL);