changeset 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 248c3f88ce99
children 4e7590473515
files COPYRIGHT src/gtkimhtml.c src/gtkimhtml.h
diffstat 3 files changed, 62 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Tue Aug 31 18:28:35 2004 +0000
+++ b/COPYRIGHT	Tue Aug 31 20:10:21 2004 +0000
@@ -129,6 +129,7 @@
 Luciano Miguel Ferreira Rocha
 Andrew Rodland
 Arvind Samptur
+Sam S.
 Tom Samstag
 Neil Sanchala
 Carsten Schaar
--- 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);
 
--- a/src/gtkimhtml.h	Tue Aug 31 18:28:35 2004 +0000
+++ b/src/gtkimhtml.h	Tue Aug 31 20:10:21 2004 +0000
@@ -67,6 +67,7 @@
 	GTK_IMHTML_IMAGE =     1 << 9,
 	GTK_IMHTML_SMILEY =    1 << 10,
 	GTK_IMHTML_LINKDESC =  1 << 11,
+	GTK_IMHTML_STRIKE =    1 << 12,
 	GTK_IMHTML_ALL =      -1
 } GtkIMHtmlButtons;
 
@@ -105,6 +106,7 @@
 		gboolean bold:1;
 		gboolean italic:1;
 		gboolean underline:1;
+		gboolean strike:1;
 		gchar *forecolor;
 		gchar *backcolor;
 		gchar *fontface;
@@ -570,6 +572,15 @@
 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml);
 
 /**
+ * Toggles strikethrough at the cursor location or selection in a GTK IM/HTML.
+ *
+ * @param imhtml The GTK IM/HTML.
+ *
+ * @return @c TRUE if strikethrough was turned on, or @c FALSE if it was turned off.
+ */
+gboolean gtk_imhtml_toggle_strike(GtkIMHtml *imhtml);
+
+/**
  * Toggles a foreground color at the current location or selection in a GTK
  * IM/HTML.
  *