Commit bfd66e1b authored by Andreas J. Guelzow 's avatar Andreas J. Guelzow

remove duplicate code

2012-05-11  Andreas J. Guelzow <aguelzow@pyrshep.ca>

	* src/gui-util.c (gnm_load_pango_attributes_into_buffer_filter):
	deleted
	(gnm_load_pango_attributes_into_buffer_named_filter): deleted
	(gnm_create_std_tags_for_buffer): deleted
	(gnm_load_pango_byte_to_char): deleted
	(gnm_load_pango_attributes_into_buffer): use
	go_load_pango_attributes_into_buffer
	* src/gui-util.h (gnm_create_std_tags_for_buffer): delete
	* src/sheet-control-gui.c (scg_comment_display):  use
	go_create_std_tags_for_buffer instead of gnm_create_std_tags_for_buffer

2012-05-11  Andreas J. Guelzow <aguelzow@pyrshep.ca>

	* gnumeric-expr-entry.c (gee_create_tooltip): use
	go_create_std_tags_for_buffer instead of gnm_create_std_tags_for_buffer
	* gnumeric-text-view.c (gtv_init): ditto
parent 6ecbd255
2012-05-11 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* src/gui-util.c (gnm_load_pango_attributes_into_buffer_filter):
deleted
(gnm_load_pango_attributes_into_buffer_named_filter): deleted
(gnm_create_std_tags_for_buffer): deleted
(gnm_load_pango_byte_to_char): deleted
(gnm_load_pango_attributes_into_buffer): use
go_load_pango_attributes_into_buffer
* src/gui-util.h (gnm_create_std_tags_for_buffer): delete
* src/sheet-control-gui.c (scg_comment_display): use
go_create_std_tags_for_buffer instead of gnm_create_std_tags_for_buffer
2012-05-11 Morten Welinder <terra@gnome.org>
* src/mstyle.c (gnm_style_update): Make hashing half-way decent.
......
......@@ -712,85 +712,10 @@ gnumeric_textview_set_text (GtkTextView *text_view, char const *txt)
txt, -1);
}
static gboolean
gnm_load_pango_attributes_into_buffer_filter (PangoAttribute *attribute,
G_GNUC_UNUSED gpointer data)
{
return ((PANGO_ATTR_FOREGROUND == attribute->klass->type) ||
(PANGO_ATTR_UNDERLINE == attribute->klass->type) ||
(PANGO_ATTR_RISE == 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) ||
(PANGO_ATTR_WEIGHT == attribute->klass->type) ||
(PANGO_ATTR_STRIKETHROUGH == attribute->klass->type));
}
#ifndef HAVE_PANGO_WEIGHT_THIN_ETC
#define PANGO_WEIGHT_THIN 100
#define PANGO_WEIGHT_BOOK 380
#define PANGO_WEIGHT_MEDIUM 500
#define PANGO_WEIGHT_ULTRAHEAVY 1000
#endif
void
gnm_create_std_tags_for_buffer (GtkTextBuffer *buffer)
{
gtk_text_buffer_create_tag (buffer, "PANGO_STYLE_NORMAL", "style", PANGO_STYLE_NORMAL,
"style-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_STYLE_ITALIC", "style", PANGO_STYLE_ITALIC,
"style-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_STRIKETHROUGH_TRUE", "strikethrough", TRUE,
"strikethrough-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_STRIKETHROUGH_FALSE", "strikethrough", FALSE,
"strikethrough-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_THIN", "weight", PANGO_WEIGHT_THIN,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_ULTRALIGHT", "weight", PANGO_WEIGHT_ULTRALIGHT,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_LIGHT", "weight", PANGO_WEIGHT_LIGHT,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_BOOK", "weight", PANGO_WEIGHT_BOOK,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_NORMAL", "weight", PANGO_WEIGHT_NORMAL,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_MEDIUM", "weight", PANGO_WEIGHT_MEDIUM,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_SEMIBOLD", "weight", PANGO_WEIGHT_SEMIBOLD,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_BOLD", "weight", PANGO_WEIGHT_BOLD,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_ULTRABOLD", "weight", PANGO_WEIGHT_ULTRABOLD,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_HEAVY", "weight", PANGO_WEIGHT_HEAVY,
"weight-set", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "PANGO_WEIGHT_ULTRAHEAVY", "weight", PANGO_WEIGHT_ULTRAHEAVY,
"weight-set", TRUE, NULL);
}
static gint
gnm_load_pango_byte_to_char (gchar const *str, gint byte)
{
if (byte >= (gint) strlen (str))
return g_utf8_strlen (str, -1);
return g_utf8_pointer_to_offset (str,
g_utf8_prev_char (str + byte + 1));
}
void
gnm_load_pango_attributes_into_buffer (PangoAttrList *markup, GtkTextBuffer *buffer, gchar const *str)
{
PangoAttrIterator * iter;
PangoAttrList *copied_markup;
PangoAttrList *our_markup;
char *str_retrieved = NULL;
if (markup == NULL)
return;
gchar *str_retrieved;
if (str == NULL) {
GtkTextIter start, end;
......@@ -800,169 +725,8 @@ gnm_load_pango_attributes_into_buffer (PangoAttrList *markup, GtkTextBuffer *bu
(buffer, &start, &end, TRUE);
}
/* 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_named_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) {
GSList *ptr;
gint start, end;
GtkTextIter start_iter, end_iter;
char const *name;
pango_attr_iterator_range (iter, &start, &end);
start = gnm_load_pango_byte_to_char
(str, start);
end = gnm_load_pango_byte_to_char (str, 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;
int val;
switch (attribute->klass->type) {
case PANGO_ATTR_STYLE:
name = (((PangoAttrInt *)attribute)->value
== PANGO_STYLE_NORMAL)
? "PANGO_STYLE_NORMAL" :
"PANGO_STYLE_ITALIC";
tag = gtk_text_tag_table_lookup
(gtk_text_buffer_get_tag_table (buffer),
name);
gtk_text_buffer_apply_tag (buffer, tag,
&start_iter, &end_iter);
break;
case PANGO_ATTR_STRIKETHROUGH:
name = (((PangoAttrInt *)attribute)->value) ?
"PANGO_STRIKETHROUGH_TRUE" :
"PANGO_STRIKETHROUGH_FALSE";
tag = gtk_text_tag_table_lookup
(gtk_text_buffer_get_tag_table (buffer),
name);
gtk_text_buffer_apply_tag (buffer, tag,
&start_iter, &end_iter);
break;
case PANGO_ATTR_WEIGHT:
val = ((PangoAttrInt *)attribute)->value;
if (val < (PANGO_WEIGHT_THIN + PANGO_WEIGHT_ULTRALIGHT)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_THIN",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_ULTRALIGHT + PANGO_WEIGHT_LIGHT)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_ULTRALIGHT",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_LIGHT + PANGO_WEIGHT_BOOK)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_LIGHT",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_BOOK + PANGO_WEIGHT_NORMAL)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_BOOK",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_NORMAL + PANGO_WEIGHT_MEDIUM)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_NORMAL",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_MEDIUM + PANGO_WEIGHT_SEMIBOLD)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_MEDIUM",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_SEMIBOLD + PANGO_WEIGHT_BOLD)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_SEMIBOLD",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_BOLD + PANGO_WEIGHT_ULTRABOLD)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_BOLD",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_ULTRABOLD + PANGO_WEIGHT_HEAVY)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_ULTRABOLD",
&start_iter, &end_iter);
else if (val < (PANGO_WEIGHT_HEAVY + PANGO_WEIGHT_ULTRAHEAVY)/2)
gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_HEAVY",
&start_iter, &end_iter);
else gtk_text_buffer_apply_tag_by_name (buffer,"PANGO_WEIGHT_ULTRAHEAVY",
&start_iter, &end_iter);
break;
default:
break;
}
}
g_slist_free_full (attr, (GDestroyNotify)pango_attribute_destroy);
}
} while (pango_attr_iterator_next (iter));
pango_attr_iterator_destroy (iter);
pango_attr_list_unref (our_markup);
}
go_load_pango_attributes_into_buffer (markup, buffer, str);
/* For other styles (that are not at true/false type styles) we use unnamed styles */
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;
case PANGO_ATTR_UNDERLINE:
g_object_set (G_OBJECT (tag),
"underline",
((PangoAttrInt *)attribute)->value,
"underline-set", TRUE,
NULL);
break;
case PANGO_ATTR_RISE:
g_object_set (G_OBJECT (tag),
"rise",
((PangoAttrInt *)attribute)->value,
"rise-set", TRUE,
NULL);
break;
default:
break;
}
}
pango_attr_iterator_range (iter, &start, &end);
start = gnm_load_pango_byte_to_char
(str, start);
end = gnm_load_pango_byte_to_char (str, 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);
g_slist_free_full (attr, (GDestroyNotify)pango_attribute_destroy);
}
} while (pango_attr_iterator_next (iter));
pango_attr_iterator_destroy (iter);
pango_attr_list_unref (our_markup);
}
g_free (str_retrieved);
}
......
......@@ -82,7 +82,6 @@ void gnm_load_pango_attributes_into_buffer (PangoAttrList *markup,
GtkTextBuffer *buffer,
gchar const *str);
PangoAttrList *gnm_get_pango_attributes_from_buffer (GtkTextBuffer *buffer);
void gnm_create_std_tags_for_buffer (GtkTextBuffer *buffer);
void focus_on_entry (GtkEntry *entry);
......
......@@ -3019,7 +3019,7 @@ scg_comment_display (SheetControlGUI *scg, GnmComment *cc,
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text), GTK_WRAP_NONE);
gtk_text_view_set_editable (GTK_TEXT_VIEW (text), FALSE);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
gnm_create_std_tags_for_buffer (buffer);
go_create_std_tags_for_buffer (buffer);
g_object_get (G_OBJECT (cc), "text", &comment_text,
"markup", &comment_markup, NULL);
......
2012-05-11 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* gnumeric-expr-entry.c (gee_create_tooltip): use
go_create_std_tags_for_buffer instead of gnm_create_std_tags_for_buffer
* gnumeric-text-view.c (gtv_init): ditto
2012-04-21 Morten Welinder <terra@gnome.org>
* Release 1.11.3
......
......@@ -817,7 +817,7 @@ gee_create_tooltip (GnmExprEntry *gee, gchar const *str,
if (pango_parse_markup (string->str, -1, 0,
&attr_list, &text,
NULL, NULL)) {
gnm_create_std_tags_for_buffer (buffer);
go_create_std_tags_for_buffer (buffer);
gtk_text_buffer_set_text (buffer, text, -1);
gnm_load_pango_attributes_into_buffer (attr_list, buffer, text);
g_free (text);
......
......@@ -346,7 +346,7 @@ gtv_init (GnmTextView *gtv)
gtv->view = GTK_TEXT_VIEW (gtk_text_view_new ());
gtv->buffer = gtk_text_view_get_buffer (gtv->view);
gnm_create_std_tags_for_buffer (gtv->buffer);
go_create_std_tags_for_buffer (gtv->buffer);
gtv->italic = gtv_build_toggle_button (tb, gtv, GTK_STOCK_ITALIC,
G_CALLBACK (cb_gtv_set_italic));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment