[gnumeric] Fixed Conflicts:



commit 45abebec0907b99caad0f0472815f9108dc64974
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Wed Apr 22 10:18:20 2009 -0600

    Fixed Conflicts:
    	ChangeLog
---
 ChangeLog                      |    7 ++
 NEWS                           |    2 +
 src/dialogs/ChangeLog          |    8 ++
 src/dialogs/dialog-so-styled.c |   79 ++++++++++++++++++--
 src/gui-util.c                 |  158 +++++++++++++++++++++++++++++++---------
 5 files changed, 212 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 89ab960..8410d7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-04-22  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/gui-util.c (gnm_load_pango_attributes_into_buffer):
+	  we need to create some labelled tags for off/on styles
+	(gnm_load_pango_attributes_into_buffer_named_filter): new
+	(gnm_store_text_tag_attr_in_pango): handle style attribute
+
 2009-04-22  Morten Welinder  <terra gnome org>
 
 	* src/wbc-gtk.c (wbcg_get_scg): Fix warning on exit.
diff --git a/NEWS b/NEWS
index 6bbf359..9b7e514 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +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
 
 Jean:
 	* Variable sheet sizes.
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 2a99c83..78dfd43 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,11 @@
+2009-04-22  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dialog-so-styled.c (DialogSOStyled): add button field
+	(cb_dialog_so_styled_text_widget_mark_set): new
+	(cb_dialog_so_styled_text_widget_set_italic): new
+	(dialog_so_styled_text_widget): add toolbar
+	(dialog_so_styled): show all widgets on the added page 
+	
 2009-04-21  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* dialog-so-styled.c (DialogSOStyled): include original attributes
diff --git a/src/dialogs/dialog-so-styled.c b/src/dialogs/dialog-so-styled.c
index f7c4f8f..1660051 100644
--- a/src/dialogs/dialog-so-styled.c
+++ b/src/dialogs/dialog-so-styled.c
@@ -41,6 +41,9 @@ typedef struct {
 	GOStyle		*orig_style;
 	char    *orig_text;
 	PangoAttrList *orig_attributes;
+	GtkTextBuffer *buffer;
+	
+	GtkToggleToolButton *italic;
 } DialogSOStyled;
 
 #define GNM_SO_STYLED_KEY "gnm-so-styled-key"
@@ -96,31 +99,95 @@ cb_dialog_so_styled_text_widget_changed (GtkTextBuffer *buffer, DialogSOStyled *
 	pango_attr_list_unref (attr);
 }
 
+static void
+cb_dialog_so_styled_text_widget_mark_set (GtkTextBuffer *buffer,
+					  G_GNUC_UNUSED GtkTextIter   *location,
+					  G_GNUC_UNUSED GtkTextMark   *mark,
+					  DialogSOStyled *state)
+{
+	GtkTextIter start, end;
+	gtk_text_buffer_get_selection_bounds (state->buffer, &start, &end);
+	
+	{ /* 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 
+			(state->italic, 
+			 (tag_italic != NULL) && gtk_text_iter_has_tag (&start, tag_italic));
+	}
+}
+
+static void
+cb_dialog_so_styled_text_widget_set_italic (GtkToggleToolButton *toolbutton, DialogSOStyled *state)
+{
+	GtkTextIter start, end;
+
+	if (gtk_text_buffer_get_selection_bounds (state->buffer, &start, &end)) {
+		GtkTextTag *tag_italic = gtk_text_tag_table_lookup 
+			(gtk_text_buffer_get_tag_table (state->buffer), "PANGO_STYLE_ITALIC");
+		GtkTextTag *tag_normal = gtk_text_tag_table_lookup 
+			(gtk_text_buffer_get_tag_table (state->buffer), "PANGO_STYLE_NORMAL");
+		if (tag_italic == NULL)
+			tag_italic = gtk_text_buffer_create_tag (state->buffer, "PANGO_STYLE_ITALIC", 
+								 "style", PANGO_STYLE_ITALIC, 
+								 "style-set", TRUE, NULL);
+		if (tag_normal == NULL)
+			tag_normal = gtk_text_buffer_create_tag (state->buffer, "PANGO_STYLE_NORMAL", 
+								 "style", PANGO_STYLE_NORMAL, 
+								 "style-set", TRUE, NULL);
+		
+		if (gtk_text_iter_has_tag (&start, tag_italic)) {
+			gtk_text_buffer_remove_tag (state->buffer, tag_italic,
+						    &start, &end);
+			gtk_text_buffer_apply_tag (state->buffer, tag_normal, &start, &end);
+		} else {
+			gtk_text_buffer_remove_tag (state->buffer, tag_normal,
+						    &start, &end);
+			gtk_text_buffer_apply_tag (state->buffer, tag_italic, &start, &end);
+		}
+		cb_dialog_so_styled_text_widget_changed (state->buffer, state);
+	}
+}
+
 static GtkWidget *
 dialog_so_styled_text_widget (DialogSOStyled *state)
 {
+	GtkWidget *vb = gtk_vbox_new (FALSE, 0);
+	GtkWidget *tb = gtk_toolbar_new ();
 	GtkWidget *tv = gtk_text_view_new ();
-	GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
 	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);
 
 	gtk_container_set_border_width (GTK_CONTAINER (tv), 5);
 	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), GTK_WRAP_WORD_CHAR);
 
 	g_object_get (state->so, "text", &strval, NULL);
 	state->orig_text = g_strdup (strval);
-	gtk_text_buffer_set_text (buffer, strval, -1);
+	gtk_text_buffer_set_text (state->buffer, strval, -1);
 	g_free (strval);
 
 	g_object_get (state->so, "markup", &markup, NULL);
 	state->orig_attributes = markup;
 	pango_attr_list_ref (state->orig_attributes);
-	gnm_load_pango_attributes_into_buffer (markup, buffer);
+	gnm_load_pango_attributes_into_buffer (markup, state->buffer);
 
-	g_signal_connect (G_OBJECT (buffer), "changed",
+	g_signal_connect (G_OBJECT (state->buffer), "changed",
 			  G_CALLBACK (cb_dialog_so_styled_text_widget_changed), state);
+	g_signal_connect (G_OBJECT (state->buffer), "mark_set",
+			  G_CALLBACK (cb_dialog_so_styled_text_widget_mark_set), state);
 
-	return tv;
+	gtk_box_pack_start (GTK_BOX (vb), tb, FALSE, TRUE, 0);
+	gtk_box_pack_start (GTK_BOX (vb), tv, TRUE, TRUE, 0);
+	return vb;
 }
 
 void
@@ -163,7 +230,7 @@ dialog_so_styled (WBCGtk *wbcg,
 
 	if (extent == SO_STYLED_TEXT) {
 		GtkWidget *text_w = dialog_so_styled_text_widget (state);
-		gtk_widget_show (text_w);
+		gtk_widget_show_all (text_w);
 		if (GTK_IS_NOTEBOOK (editor))
 			gtk_notebook_append_page (GTK_NOTEBOOK (editor),
 						  text_w,
diff --git a/src/gui-util.c b/src/gui-util.c
index 4dab183..c60dc3d 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -668,6 +668,12 @@ gnm_load_pango_attributes_into_buffer_filter (PangoAttribute *attribute,
 {
 	return (PANGO_ATTR_FOREGROUND == attribute->klass->type);
 }
+static gboolean
+gnm_load_pango_attributes_into_buffer_named_filter (PangoAttribute *attribute, 
+						    G_GNUC_UNUSED gpointer data)
+{
+	return (PANGO_ATTR_STYLE == attribute->klass->type);
+}
 
 void 
 gnm_load_pango_attributes_into_buffer (PangoAttrList  *markup, GtkTextBuffer *buffer) 
@@ -678,49 +684,120 @@ gnm_load_pango_attributes_into_buffer (PangoAttrList  *markup, GtkTextBuffer *bu
 
 	if (markup == NULL)
 		return; 
+
+/* For some styles we create named tags. The names are taken from the Pango enums */
+
 	copied_markup = pango_attr_list_copy (markup);
 	our_markup = pango_attr_list_filter (copied_markup, 
-					     gnm_load_pango_attributes_into_buffer_filter, 
+					     gnm_load_pango_attributes_into_buffer_named_filter, 
 					     NULL);
 	pango_attr_list_unref (copied_markup);
-	if (our_markup == NULL)
-		return; 
+	if (our_markup != NULL) {
+		iter = pango_attr_list_get_iterator (our_markup);
+		
+		do {
+			GSList *attr = pango_attr_iterator_get_attrs (iter);
+			if (attr != NULL) {
+				GSList *ptr;
+				gint start, end;
+				GtkTextIter start_iter, end_iter;
+
+				pango_attr_iterator_range (iter, &start, &end);
+				gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, start);
+				gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, end);
+
+				for (ptr = attr; ptr != NULL; ptr = ptr->next) {
+					PangoAttribute *attribute = ptr->data;
+					GtkTextTag *tag;
+
+					switch (attribute->klass->type) {
+					case PANGO_ATTR_STYLE:
+						switch (((PangoAttrInt *)attribute)->value) {
+						case PANGO_STYLE_ITALIC:
+							tag = gtk_text_tag_table_lookup 
+								(gtk_text_buffer_get_tag_table (buffer), 
+								 "PANGO_STYLE_ITALIC");
+							if (tag == NULL)
+								tag = gtk_text_buffer_create_tag 
+									(buffer, 
+									 "PANGO_STYLE_ITALIC", 
+									 "style", PANGO_STYLE_ITALIC,
+									 "style-set", TRUE,
+									 NULL);
+							gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
+							break;
+						case PANGO_STYLE_NORMAL:
+							tag = gtk_text_tag_table_lookup 
+								(gtk_text_buffer_get_tag_table (buffer), 
+								 "PANGO_STYLE_NORMAL");
+							if (tag == NULL)
+								tag = gtk_text_buffer_create_tag 
+									(buffer, 
+									 "PANGO_STYLE_NORMAL", 
+									 "style", PANGO_STYLE_NORMAL,
+									 "style-set", TRUE,
+									 NULL);
+							gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
+							break;
+						default:
+							break;
+						}
+						break;
+					default:
+						break;
+					}
+				}
+				go_slist_free_custom (attr, (GFreeFunc)pango_attribute_destroy);
+			}
+		} while (pango_attr_iterator_next (iter));
+		pango_attr_iterator_destroy (iter);
+		pango_attr_list_unref (our_markup);
+	}
+
+/* For other styles (that are not at true/faclse type styles) we use unnamed styles */
 
-	iter = pango_attr_list_get_iterator (our_markup);
-
-	do {
-		GSList *attr = pango_attr_iterator_get_attrs (iter);
-		if (attr != NULL) {
-			char *string;
-			GSList *ptr;
-			gint start, end;
-			GtkTextIter start_iter, end_iter;
-			GtkTextTag *tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
-			for (ptr = attr; ptr != NULL; ptr = ptr->next) {
-				PangoAttribute *attribute = ptr->data;
-				switch (attribute->klass->type) {
-				case PANGO_ATTR_FOREGROUND:
-					string = pango_color_to_string 
-						(&((PangoAttrColor *)attribute)->color);
-					g_object_set (G_OBJECT (tag), 
-						      "foreground", string,
-						      "foreground-set", TRUE,
-						      NULL);
-					g_free (string);
-					break;
-				default:
-					break;
+	copied_markup = pango_attr_list_copy (markup);
+	our_markup = pango_attr_list_filter (copied_markup, 
+					     gnm_load_pango_attributes_into_buffer_filter, 
+					     NULL);
+	pango_attr_list_unref (copied_markup);
+	if (our_markup != NULL) {
+		iter = pango_attr_list_get_iterator (our_markup);
+		
+		do {
+			GSList *attr = pango_attr_iterator_get_attrs (iter);
+			if (attr != NULL) {
+				char *string;
+				GSList *ptr;
+				gint start, end;
+				GtkTextIter start_iter, end_iter;
+				GtkTextTag *tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
+				for (ptr = attr; ptr != NULL; ptr = ptr->next) {
+					PangoAttribute *attribute = ptr->data;
+					switch (attribute->klass->type) {
+					case PANGO_ATTR_FOREGROUND:
+						string = pango_color_to_string 
+							(&((PangoAttrColor *)attribute)->color);
+						g_object_set (G_OBJECT (tag), 
+							      "foreground", string,
+							      "foreground-set", TRUE,
+							      NULL);
+						g_free (string);
+						break;
+					default:
+						break;
+					}
 				}
+				pango_attr_iterator_range (iter, &start, &end);
+				gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, start);
+				gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, end);
+				gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
+				go_slist_free_custom (attr, (GFreeFunc)pango_attribute_destroy);
 			}
-			pango_attr_iterator_range (iter, &start, &end);
-			gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, start);
-			gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, end);
-			gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
-			go_slist_free_custom (attr, (GFreeFunc)pango_attribute_destroy);
-		}
-	} while (pango_attr_iterator_next (iter));
-	pango_attr_iterator_destroy (iter);
-	pango_attr_list_unref (our_markup);
+		} while (pango_attr_iterator_next (iter));
+		pango_attr_iterator_destroy (iter);
+		pango_attr_list_unref (our_markup);
+	}
 }
 
 static void
@@ -745,6 +822,15 @@ gnm_store_text_tag_attr_in_pango (PangoAttrList *list, GtkTextTag *tag, GtkTextI
 		pango_attr_list_change (list, attr);
 		gdk_color_free (color);
 	}
+	g_object_get (G_OBJECT (tag), "style-set", &is_set, NULL);
+	if (is_set) {
+		int style;
+		g_object_get (G_OBJECT (tag), "style", &style, NULL);
+		attr =  pango_attr_style_new (style);
+		attr->start_index = x;
+		attr->end_index = y;
+		pango_attr_list_change (list, attr);
+	}
 }
 
 PangoAttrList *



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