[gnumeric] Include "strikethrough" button in the properties dialog for sheet object labels



commit 4139fdd813f05fe90db0ebb0a2ec9ef7751d1dbc
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Thu Apr 23 10:35:01 2009 -0600

    Include "strikethrough" button in the properties dialog for sheet object labels
    
        2009-04-23  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        	* dialog-so-styled.c (DialogSOStyled): add button field
        	(gnm_toggle_tool_button_set_active_no_signal): new
        	(cb_dialog_so_styled_text_widget_mark_set): block signals when
        	  activating buttons and handle strikethrough button
        	(cb_dialog_so_styled_text_widget_set_strikethrough): new
        	(dialog_so_styled_build_toggle_button): new
        	(dialog_so_styled_text_widget): build strikethrough button
        	  and use dialog_so_styled_build_toggle_button
---
 NEWS                           |    4 +-
 src/dialogs/ChangeLog          |   11 +++++
 src/dialogs/dialog-so-styled.c |   81 ++++++++++++++++++++++++++++++++++++----
 3 files changed, 86 insertions(+), 10 deletions(-)

diff --git a/NEWS b/NEWS
index 9b7e514..770b99c 100644
--- a/NEWS
+++ b/NEWS
@@ -8,8 +8,8 @@ Andreas:
 	* Quieten GTK warning [#579152]
 	* Print text in sheet object label [#144787]
 	* Implement editing of a sheet object label
-	* Include an "italic" button in the properties dialog for sheet
-	  object labels
+	* Include "italic" and "strikethrough" buttons in the properties 
+	  dialog for sheet object labels
 
 Jean:
 	* Variable sheet sizes.
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 13718d2..8b21c1f 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,14 @@
+2009-04-23  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dialog-so-styled.c (DialogSOStyled): add button field
+	(gnm_toggle_tool_button_set_active_no_signal): new
+	(cb_dialog_so_styled_text_widget_mark_set): block signals when
+	  activating buttons and handle strikethrough button
+	(cb_dialog_so_styled_text_widget_set_strikethrough): new
+	(dialog_so_styled_build_toggle_button): new
+	(dialog_so_styled_text_widget): build strikethrough button
+	  and use dialog_so_styled_build_toggle_button
+
 2009-04-22  Morten Welinder  <terra gnome org>
 
 	* dialog-sheet-resize.c (dialog_sheet_resize): Apply a minimum
diff --git a/src/dialogs/dialog-so-styled.c b/src/dialogs/dialog-so-styled.c
index 1660051..52e1367 100644
--- a/src/dialogs/dialog-so-styled.c
+++ b/src/dialogs/dialog-so-styled.c
@@ -44,6 +44,7 @@ typedef struct {
 	GtkTextBuffer *buffer;
 	
 	GtkToggleToolButton *italic;
+	GtkToggleToolButton *strikethrough;
 } DialogSOStyled;
 
 #define GNM_SO_STYLED_KEY "gnm-so-styled-key"
@@ -100,6 +101,18 @@ cb_dialog_so_styled_text_widget_changed (GtkTextBuffer *buffer, DialogSOStyled *
 }
 
 static void
+gnm_toggle_tool_button_set_active_no_signal (GtkToggleToolButton *button,
+					     gboolean is_active,
+					     DialogSOStyled *state)
+{
+	gulong handler_id = g_signal_handler_find (button, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, state);
+
+	g_signal_handler_block (button, handler_id);
+	gtk_toggle_tool_button_set_active (button, is_active);
+	g_signal_handler_unblock (button, handler_id);
+}
+
+static void
 cb_dialog_so_styled_text_widget_mark_set (GtkTextBuffer *buffer,
 					  G_GNUC_UNUSED GtkTextIter   *location,
 					  G_GNUC_UNUSED GtkTextMark   *mark,
@@ -111,9 +124,17 @@ cb_dialog_so_styled_text_widget_mark_set (GtkTextBuffer *buffer,
 	{ /* Handling italic button */
 		GtkTextTag *tag_italic = gtk_text_tag_table_lookup 
 			(gtk_text_buffer_get_tag_table (state->buffer), "PANGO_STYLE_ITALIC");
-		gtk_toggle_tool_button_set_active 
+		gnm_toggle_tool_button_set_active_no_signal
 			(state->italic, 
-			 (tag_italic != NULL) && gtk_text_iter_has_tag (&start, tag_italic));
+			 (tag_italic != NULL) && gtk_text_iter_has_tag (&start, tag_italic), state);
+	}
+	{ /* Handling strikethrough button */
+		GtkTextTag *tag_strikethrough = gtk_text_tag_table_lookup 
+			(gtk_text_buffer_get_tag_table (state->buffer), "PANGO_STRIKETHROUGH_TRUE");
+		gnm_toggle_tool_button_set_active_no_signal
+			(state->strikethrough, 
+			 (tag_strikethrough != NULL) && gtk_text_iter_has_tag (&start, tag_strikethrough), 
+			 state);
 	}
 }
 
@@ -149,6 +170,50 @@ cb_dialog_so_styled_text_widget_set_italic (GtkToggleToolButton *toolbutton, Dia
 	}
 }
 
+static void
+cb_dialog_so_styled_text_widget_set_strikethrough (GtkToggleToolButton *toolbutton, DialogSOStyled *state)
+{
+	GtkTextIter start, end;
+
+	if (gtk_text_buffer_get_selection_bounds (state->buffer, &start, &end)) {
+		GtkTextTag *tag_no_strikethrough = gtk_text_tag_table_lookup 
+			(gtk_text_buffer_get_tag_table (state->buffer), "PANGO_STRIKETHROUGH_FALSE");
+		GtkTextTag *tag_strikethrough = gtk_text_tag_table_lookup 
+			(gtk_text_buffer_get_tag_table (state->buffer), "PANGO_STRIKETHROUGH_TRUE");
+		if (tag_no_strikethrough == NULL)
+			tag_no_strikethrough = gtk_text_buffer_create_tag (state->buffer, "PANGO_STRIKETHROUGH_FALSE", 
+								 "strikethrough", FALSE, 
+								 "strikethrough-set", TRUE, NULL);
+		if (tag_strikethrough == NULL)
+			tag_strikethrough = gtk_text_buffer_create_tag (state->buffer, "PANGO_STRIKETHROUGH_TRUE", 
+								 "strikethrough", TRUE, 
+								 "strikethrough-set", TRUE, NULL);
+		
+		if (gtk_text_iter_has_tag (&start, tag_strikethrough)) {
+			gtk_text_buffer_remove_tag (state->buffer, tag_strikethrough,
+						    &start, &end);
+			gtk_text_buffer_apply_tag (state->buffer, tag_no_strikethrough, &start, &end);
+		} else {
+			gtk_text_buffer_remove_tag (state->buffer, tag_no_strikethrough,
+						    &start, &end);
+			gtk_text_buffer_apply_tag (state->buffer, tag_strikethrough, &start, &end);
+		}
+		cb_dialog_so_styled_text_widget_changed (state->buffer, state);
+	}
+}
+
+static GtkToggleToolButton *
+dialog_so_styled_build_toggle_button (GtkWidget *tb, DialogSOStyled *state, char const *button_name, GCallback cb)
+{
+	GtkToolItem * tb_button;
+
+	tb_button = gtk_toggle_tool_button_new_from_stock (button_name);
+	gtk_toolbar_insert(GTK_TOOLBAR(tb), tb_button, -1);
+	g_signal_connect (G_OBJECT (tb_button), "toggled", cb, state);
+	return GTK_TOGGLE_TOOL_BUTTON (tb_button);
+}
+
+
 static GtkWidget *
 dialog_so_styled_text_widget (DialogSOStyled *state)
 {
@@ -157,15 +222,15 @@ dialog_so_styled_text_widget (DialogSOStyled *state)
 	GtkWidget *tv = gtk_text_view_new ();
 	char *strval;
 	PangoAttrList  *markup;
-	GtkToolItem * tb_button;
 
 	state->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
 
-	tb_button = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_ITALIC);
-	gtk_toolbar_insert(GTK_TOOLBAR(tb), tb_button, -1);
-	g_signal_connect (G_OBJECT (tb_button), "toggled",
-			  G_CALLBACK (cb_dialog_so_styled_text_widget_set_italic), state);
-	state->italic = GTK_TOGGLE_TOOL_BUTTON (tb_button);
+	state->italic = dialog_so_styled_build_toggle_button 
+		(tb, state, GTK_STOCK_ITALIC, 
+		 G_CALLBACK (cb_dialog_so_styled_text_widget_set_italic));
+	state->strikethrough = dialog_so_styled_build_toggle_button 
+		(tb, state, GTK_STOCK_STRIKETHROUGH, 
+		 G_CALLBACK (cb_dialog_so_styled_text_widget_set_strikethrough));
 
 	gtk_container_set_border_width (GTK_CONTAINER (tv), 5);
 	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), GTK_WRAP_WORD_CHAR);



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