[gnumeric] GnmColor: Eliminate gdk_color field.



commit 326c9b04afbc594acbb7fee51358895f2aaf2316
Author: Morten Welinder <terra gnome org>
Date:   Tue Sep 1 22:22:54 2009 -0400

    GnmColor: Eliminate gdk_color field.

 ChangeLog                             |    3 +
 NEWS                                  |    1 +
 plugins/excel/ms-chart.c              |    2 +-
 plugins/excel/ms-excel-read.c         |   50 +++++++++------
 plugins/excel/ms-excel-write.c        |   12 ++--
 plugins/excel/xlsx-read.c             |    9 ++-
 plugins/html/html.c                   |   12 ++--
 plugins/openoffice/openoffice-write.c |   10 ++-
 src/dialogs/dialog-cell-format.c      |   25 +++----
 src/dialogs/dialog-sheet-order.c      |   11 ++--
 src/gui-util.c                        |    2 +-
 src/item-edit.c                       |    6 +-
 src/mstyle.c                          |   12 ++--
 src/pattern.c                         |   17 +++--
 src/sheet-control-gui.c               |    9 ++-
 src/style-border.c                    |   15 +++--
 src/style-color.c                     |  112 ++++++++++++--------------------
 src/style-color.h                     |    5 +-
 src/wbc-gtk.c                         |   18 +++--
 src/xml-io.c                          |   14 ++--
 src/xml-sax-read.c                    |    2 +-
 21 files changed, 171 insertions(+), 176 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 092f420..dfaeacf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2009-09-01  Morten Welinder  <terra gnome org>
 
+	* src/style-color.h (GnmColor): Eliminate gdk_color filed.  All
+	users changed to use go_color.
+
 	* src/style-color.c (style_color_new_uninterned): Cleanup.
 
 2009-09-01  Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/NEWS b/NEWS
index 08582a1..0b5e07a 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Andreas:
 
 Morten:
 	* Fix menu sensitivity problem.  [#593624]
+	* Simplify GnmColor.
 
 --------------------------------------------------------------------------
 Gnumeric 1.9.11
diff --git a/plugins/excel/ms-chart.c b/plugins/excel/ms-chart.c
index 20a30e9..9dd924c 100644
--- a/plugins/excel/ms-chart.c
+++ b/plugins/excel/ms-chart.c
@@ -1070,7 +1070,7 @@ ms_chart_map_color (XLChartReadState const *s, guint32 raw, guint32 alpha)
 	if ((~0x7ffffff) & raw) {
 		GnmColor *c = excel_palette_get (s->container.importer,
 			(0x7ffffff & raw));
-		res = GO_GDK_TO_UINT (c->gdk_color);
+		res = c->go_color;
 		style_color_unref (c);
 	} else {
 		guint8 r, g, b;
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index a871223..875242d 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -346,9 +346,9 @@ ms_sheet_map_color (ExcelReadSheet const *esheet, MSObj const *obj, MSObjAttrID
 		GnmColor *c = excel_palette_get (esheet->container.importer,
 			(0x7ffffff & attr->v.v_uint));
 
-		r = c->gdk_color.red >> 8;
-		g = c->gdk_color.green >> 8;
-		b = c->gdk_color.blue >> 8;
+		r = GO_UINT_RGBA_R (c->go_color);
+		g = GO_UINT_RGBA_G (c->go_color);
+		b = GO_UINT_RGBA_B (c->go_color);
 		style_color_unref (c);
 	} else {
 		r = (attr->v.v_uint)       & 0xff;
@@ -1712,9 +1712,12 @@ excel_palette_get (GnmXLImporter *importer, gint idx)
 		g_return_val_if_fail (pal->gnm_colors[idx],
 				      style_color_black ());
 		d (5, {
-			GnmColor *c = pal->gnm_colors[idx];
-			fprintf (stderr,"New color in slot %d: RGB= %x,%x,%x\n",
-				idx, c->gdk_color.red, c->gdk_color.green, c->gdk_color.blue);
+			const GnmColor *c = pal->gnm_colors[idx];
+			g_printerr ("New color in slot %d: RGB= %x,%x,%x\n",
+				    idx,
+				    GO_UINT_RGBA_R (c->go_color),
+				    GO_UINT_RGBA_G (c->go_color),
+				    GO_UINT_RGBA_B (c->go_color));
 		});
 	}
 
@@ -1945,10 +1948,16 @@ excel_get_style_from_xf (ExcelReadSheet *esheet, BiffXFData const *xf)
 	g_return_val_if_fail (back_color && pattern_color && font_color, NULL);
 
 	d (4, fprintf (stderr,"back = #%02x%02x%02x, pat = #%02x%02x%02x, font = #%02x%02x%02x, pat_style = %d\n",
-		      back_color->gdk_color.red>>8, back_color->gdk_color.green>>8, back_color->gdk_color.blue>>8,
-		      pattern_color->gdk_color.red>>8, pattern_color->gdk_color.green>>8, pattern_color->gdk_color.blue>>8,
-		      font_color->gdk_color.red>>8, font_color->gdk_color.green>>8, font_color->gdk_color.blue>>8,
-		      xf->fill_pattern_idx););
+		       GO_UINT_RGBA_R (back_color->go_color),
+		       GO_UINT_RGBA_G (back_color->go_color),
+		       GO_UINT_RGBA_B (back_color->go_color),
+		       GO_UINT_RGBA_R (pattern_color->go_color),
+		       GO_UINT_RGBA_G (pattern_color->go_color),
+		       GO_UINT_RGBA_B (pattern_color->go_color),
+		       GO_UINT_RGBA_R (font_color->go_color),
+		       GO_UINT_RGBA_G (font_color->go_color),
+		       GO_UINT_RGBA_B (font_color->go_color),
+		       xf->fill_pattern_idx););
 
 	gnm_style_set_font_color (mstyle, font_color);
 	gnm_style_set_back_color (mstyle, back_color);
@@ -2987,8 +2996,7 @@ ms_wb_get_font_markup (MSContainer const *c, unsigned indx)
 
 		color = (fd->color_idx == 127) ? style_color_black ()
 			: excel_palette_get (importer, fd->color_idx);
-		add_attr (attrs, pango_attr_foreground_new (
-			color->gdk_color.red, color->gdk_color.green, color->gdk_color.blue));
+		add_attr (attrs, go_color_to_pango (color->go_color, TRUE));
 		style_color_unref (color);
 
 		((ExcelFont *)fd)->attrs = attrs;
@@ -3843,8 +3851,10 @@ office 12 seems to add 8 bytes
 	 */
 	color_index = GSF_LE_GET_GUINT8 (q->data + 16);
 	color = excel_palette_get (esheet->container.importer, color_index);
-	contrast = color->gdk_color.red + color->gdk_color.green + color->gdk_color.blue;
-	if (contrast >= 0x18000)
+	contrast = GO_UINT_RGBA_R (color->go_color) +
+		GO_UINT_RGBA_G (color->go_color) +
+		GO_UINT_RGBA_B (color->go_color);
+	if (contrast >= 0x180)
 		text_color = style_color_black ();
 	else
 		text_color = style_color_white ();
@@ -3852,9 +3862,9 @@ office 12 seems to add 8 bytes
 		      "tab-foreground", text_color,
 		      "tab-background", color,
 		      NULL);
-	d (1, fprintf (stderr,"%s tab colour = %04hx:%04hx:%04hx\n",
-		      esheet->sheet->name_unquoted,
-		      color->gdk_color.red, color->gdk_color.green, color->gdk_color.blue););
+	d (1, fprintf (stderr,"%s tab colour = %08x\n",
+		       esheet->sheet->name_unquoted,
+		       color->go_color););
 
 	style_color_unref (text_color);
 	style_color_unref (color);
@@ -4774,10 +4784,8 @@ excel_read_WINDOW2 (BiffQuery *q, ExcelReadSheet *esheet, WorkbookView *wb_view)
 			pattern_color = style_color_new_i8 (r, g, b);
 		}
 		d (2, fprintf (stderr,"auto pattern color "
-			      "0x%x 0x%x 0x%x\n",
-			      pattern_color->gdk_color.red,
-			      pattern_color->gdk_color.green,
-			      pattern_color->gdk_color.blue););
+			       "0x%08x\n",
+			       pattern_color->go_color););
 		sheet_style_set_auto_pattern_color (
 			esheet->sheet, pattern_color);
 	}
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index df4af75..50dfe92 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -132,12 +132,6 @@ excel_style_variant_equal (ExcelStyleVariant const *a,
 }
 
 static guint
-gnm_color_to_bgr (GnmColor const *c)
-{
-	return ((c->gdk_color.blue & 0xff00) << 8) + (c->gdk_color.green & 0xff00) + (c->gdk_color.red >> 8);
-
-}
-static guint
 go_color_to_bgr (GOColor const c)
 {
 	guint32 abgr;
@@ -147,6 +141,12 @@ go_color_to_bgr (GOColor const c)
 	return abgr;
 }
 
+static guint
+gnm_color_to_bgr (GnmColor const *c)
+{
+	return go_color_to_bgr (c->go_color);
+}
+
 /**
  * map_pattern_to_xl
  * @i Gnumeric pattern index
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 1a609bd..6b33484 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -2823,10 +2823,11 @@ xlsx_sheet_tabcolor (GsfXMLIn *xin, xmlChar const **attrs)
 	XLSXReadState *state = (XLSXReadState *)xin->user_state;
 	GnmColor *text_color, *color = elem_color (xin, attrs);
 	if (NULL != color) {
-		int contrast = color->gdk_color.red +
-			color->gdk_color.green +
-			color->gdk_color.blue;
-		if (contrast >= 0x18000)
+		int contrast =
+			GO_UINT_RGBA_R (color->go_color) +
+			GO_UINT_RGBA_G (color->go_color) +
+			GO_UINT_RGBA_B (color->go_color);
+		if (contrast >= 0x180)
 			text_color = style_color_black ();
 		else
 			text_color = style_color_white ();
diff --git a/plugins/html/html.c b/plugins/html/html.c
index b8f665b..2696d9c 100644
--- a/plugins/html/html.c
+++ b/plugins/html/html.c
@@ -130,9 +130,9 @@ static void
 html_get_back_color (GnmStyle const *style, guint *r, guint *g, guint *b)
 {
 	GnmColor const *color = gnm_style_get_back_color (style);
-	*r = color->gdk_color.red >> 8;
-	*g = color->gdk_color.green >> 8;
-	*b = color->gdk_color.blue >> 8;
+	*r = GO_UINT_RGBA_R (color->go_color);
+	*g = GO_UINT_RGBA_G (color->go_color);
+	*b = GO_UINT_RGBA_B (color->go_color);
 }
 
 /*****************************************************************************/
@@ -399,9 +399,9 @@ html_get_border_style (GnmBorder *border)
 
 	if (border->color) {
 		guint r, g, b;
-		r = border->color->gdk_color.red >> 8;
-		g = border->color->gdk_color.green >> 8;
-		b = border->color->gdk_color.blue >> 8;
+		r = GO_UINT_RGBA_R (border->color->go_color);
+		g = GO_UINT_RGBA_G (border->color->go_color);
+		b = GO_UINT_RGBA_B (border->color->go_color);
 		g_string_append_printf (text, " #%02X%02X%02X", r, g, b);
 	}
 
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 3d3c8e5..4ef3e6c 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -415,9 +415,9 @@ gnm_xml_out_add_hex_color (GsfXMLOut *o, char const *id, GnmColor const *c)
 	else {
 		char *color;
 		color = g_strdup_printf ("#%.2x%.2x%.2x", 
-					 c->gdk_color.red/256, 
-					 c->gdk_color.green/256, 
-					 c->gdk_color.blue/256);
+					 GO_UINT_RGBA_R (c->go_color),
+					 GO_UINT_RGBA_G (c->go_color),
+					 GO_UINT_RGBA_B (c->go_color));
 		gsf_xml_out_add_cstr_unchecked (o, id, color);
 		g_free (color);
 	}
@@ -597,7 +597,9 @@ odf_get_border_format (GnmBorder   *border)
 	g_string_append_printf (str, "%.3fcm ", w);
 	g_string_append (str, border_type);
 	g_string_append_printf (str, " #%.2x%.2x%.2x",  
-				color->gdk_color.red/256, color->gdk_color.green/256, color->gdk_color.blue/256);
+				GO_UINT_RGBA_R (color->go_color),
+				GO_UINT_RGBA_G (color->go_color),
+				GO_UINT_RGBA_B (color->go_color));
 	return g_string_free (str, FALSE);
 }
 
diff --git a/src/dialogs/dialog-cell-format.c b/src/dialogs/dialog-cell-format.c
index f73fa2c..6a8e113 100644
--- a/src/dialogs/dialog-cell-format.c
+++ b/src/dialogs/dialog-cell-format.c
@@ -390,7 +390,7 @@ setup_color_pickers (FormatState *state,
 	cg = go_color_group_fetch (color_group,
 		 wb_control_view (WORKBOOK_CONTROL (state->wbcg)));
 	combo = go_combo_color_new (NULL, default_caption, 
-		def_sc ? GO_GDK_TO_UINT (def_sc->gdk_color) : GO_RGBA_BLACK, cg);
+		def_sc ? def_sc->go_color : GO_RGBA_BLACK, cg);
 	go_combo_box_set_title (GO_COMBO_BOX (combo), caption);
 
 	/* Connect to the sample canvas and redraw it */
@@ -398,8 +398,11 @@ setup_color_pickers (FormatState *state,
 		"color_changed",
 		G_CALLBACK (preview_update), state);
 
-	go_combo_color_set_color_gdk (GO_COMBO_COLOR (combo),
-		(mcolor && !mcolor->is_auto) ? &mcolor->gdk_color : NULL);
+	if (mcolor && !mcolor->is_auto)
+		go_combo_color_set_color (GO_COMBO_COLOR (combo),
+					  mcolor->go_color);
+	else
+		go_combo_color_set_color_to_default (GO_COMBO_COLOR (combo));
 
 	frame = gtk_frame_new (NULL);
 	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
@@ -1442,10 +1445,7 @@ init_border_button (FormatState *state, GnmStyleBorderLocation const i,
 		state->border.edge[i].is_selected = TRUE;
 	} else {
 		GnmColor const *c = border->color;
-		state->border.edge[i].rgba = GO_RGBA_TO_UINT(
-			c->gdk_color.red >> 8,
-			c->gdk_color.green >> 8,
-			c->gdk_color.blue >> 8, 0xff);
+		state->border.edge[i].rgba = c->go_color;
 		state->border.edge[i].is_auto_color = c->is_auto;
 		state->border.edge[i].pattern_index = border->line_type;
 		state->border.edge[i].is_selected = (border->line_type != GNM_STYLE_BORDER_NONE);
@@ -2444,7 +2444,7 @@ fmt_dialog_impl (FormatState *state, FormatDialogPosition_t pageno)
 	int i, selected;
 	char const *name;
 	gboolean has_back;
-	GdkColor *default_border_color;
+	GOColor default_border_color;
 	int default_border_style = GNM_STYLE_BORDER_THIN;
 
 	GtkWidget *tmp, *dialog = glade_xml_get_widget (state->gui, "CellFormat");
@@ -2475,7 +2475,7 @@ fmt_dialog_impl (FormatState *state, FormatDialogPosition_t pageno)
 	fmt_dialog_init_input_msg_page (state);
 	fmt_dialog_init_conditions_page (state);
 
-	default_border_color = &GTK_WIDGET (state->dialog)->style->black;
+	default_border_color = GO_GDK_TO_UINT (GTK_WIDGET (state->dialog)->style->black);
 
 	if (pageno == FD_CURRENT)
 		pageno = fmt_dialog_page;
@@ -2492,7 +2492,7 @@ fmt_dialog_impl (FormatState *state, FormatDialogPosition_t pageno)
 	for (i = MSTYLE_BORDER_TOP; i < MSTYLE_BORDER_DIAGONAL; i++) {
 		GnmBorder const *border = gnm_style_get_border (state->style, i);
 		if (!gnm_style_border_is_blank (border)) {
-			default_border_color = &border->color->gdk_color;
+			default_border_color = border->color->go_color;
 			default_border_style = border->line_type;
 			break;
 		}
@@ -2501,10 +2501,7 @@ fmt_dialog_impl (FormatState *state, FormatDialogPosition_t pageno)
 	state->border.pattern.draw_preview = NULL;
 	state->border.pattern.current_pattern = NULL;
 	state->border.pattern.state = state;
-	state->border.rgba = GO_RGBA_TO_UINT (
-		default_border_color->red   >> 8,
-		default_border_color->green >> 8,
-		default_border_color->blue  >> 8, 0xff);
+	state->border.rgba = default_border_color;
 	for (i = 0; (name = line_pattern_buttons[i].name) != NULL; ++i)
 		setup_pattern_button (gtk_widget_get_screen (GTK_WIDGET (state->dialog)),
 				      state->gui, name, &state->border.pattern,
diff --git a/src/dialogs/dialog-sheet-order.c b/src/dialogs/dialog-sheet-order.c
index 4c78cef..3189523 100644
--- a/src/dialogs/dialog-sheet-order.c
+++ b/src/dialogs/dialog-sheet-order.c
@@ -289,7 +289,8 @@ color_equal (const GdkColor *color_a, const GnmColor *color_gb)
 {
 	if (color_gb == NULL)
 		return color_a == NULL;
-	return color_a && gdk_color_equal (color_a, &color_gb->gdk_color);
+	/* FIXME: What about ->is_auto?  */
+	return color_a && GO_GDK_TO_UINT (*color_a) == color_gb->go_color;
 }
 
 static void
@@ -771,13 +772,13 @@ create_sheet_list (SheetManager *state)
 static void
 set_sheet_info_at_iter (SheetManager *state, GtkTreeIter *iter, Sheet *sheet)
 {
-	GdkColor *color = NULL;
-	GdkColor *text_color = NULL;
+	GdkColor cback, *color = NULL;
+	GdkColor cfore, *text_color = NULL;
 
 	if (sheet->tab_color)
-		color = &sheet->tab_color->gdk_color;
+		color = go_color_to_gdk (sheet->tab_color->go_color, &cback);
 	if (sheet->tab_text_color)
-		text_color = &sheet->tab_text_color->gdk_color;
+		text_color = go_color_to_gdk (sheet->tab_text_color->go_color, &cfore);
 
 	gtk_list_store_set (state->model, iter,
 			    SHEET_LOCKED, sheet->is_protected,
diff --git a/src/gui-util.c b/src/gui-util.c
index 52927ce..5bed9cc 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -611,7 +611,7 @@ go_combo_color_get_style_color (GtkWidget *go_combo_color)
 		r  = GO_UINT_RGBA_R (color); r |= (r << 8);
 		g  = GO_UINT_RGBA_G (color); g |= (g << 8);
 		b  = GO_UINT_RGBA_B (color); b |= (b << 8);
-		sc = style_color_new (r, g, b);
+		sc = style_color_new_i16 (r, g, b);
 	}
 	return sc;
 }
diff --git a/src/item-edit.c b/src/item-edit.c
index 2ae4d30..dec44b3 100644
--- a/src/item-edit.c
+++ b/src/item-edit.c
@@ -229,15 +229,13 @@ item_edit_update_bounds (GocItem *item)
 		if (entered_text != NULL && entered_text != text) {
 			int const start = strlen (entered_text);
 			GnmColor const *color = gnm_style_get_font_color (ie->style);
-			attr = pango_attr_background_new (
-				color->gdk_color.red, color->gdk_color.green, color->gdk_color.blue);
+			attr = go_color_to_pango (color->go_color, FALSE);
 			attr->start_index = start;
 			attr->end_index = G_MAXINT;
 			pango_attr_list_insert (attrs, attr);
 
 			color = gnm_style_get_back_color (ie->style);
-			attr = pango_attr_foreground_new (
-				color->gdk_color.red, color->gdk_color.green, color->gdk_color.blue);
+			attr = go_color_to_pango (color->go_color, TRUE);
 			attr->start_index = start;
 			attr->end_index = G_MAXINT;
 			pango_attr_list_insert (attrs, attr);
diff --git a/src/mstyle.c b/src/mstyle.c
index 5dc7b89..79e1448 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -1662,8 +1662,7 @@ gnm_style_get_pango_attrs (GnmStyle const *style,
 	/* See http://bugzilla.gnome.org/show_bug.cgi?id=105322 */
 	if (0) {
 		GnmColor const *fore = style->color.font;
-		add_attr (l, pango_attr_foreground_new (
-			fore->gdk_color.red, fore->gdk_color.green, fore->gdk_color.blue));
+		add_attr (l, go_color_to_pango (fore->go_color, TRUE));
 	}
 
 	/* Handle underlining.  */
@@ -1715,8 +1714,7 @@ gnm_style_generate_attrs_full (GnmStyle const *style)
 		? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL));
 	add_attr (l, pango_attr_weight_new (gnm_style_get_font_bold (style)
 		? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL));
-	add_attr (l, pango_attr_foreground_new (
-		fore->gdk_color.red, fore->gdk_color.green, fore->gdk_color.blue));
+	add_attr (l, go_color_to_pango (fore->go_color, TRUE));
 	add_attr (l, pango_attr_strikethrough_new (gnm_style_get_font_strike (style)));
 	switch (gnm_style_get_font_uline (style)) {
 	case UNDERLINE_SINGLE :
@@ -1807,9 +1805,9 @@ gnm_style_dump_color (GnmColor *color, GnmStyleElement elem)
 {
 	if (color)
 		g_printerr ("\t%s: %hx:%hx:%hx\n", gnm_style_element_name [elem],
-			 color->gdk_color.red,
-			 color->gdk_color.green,
-			 color->gdk_color.blue);
+			    GO_UINT_RGBA_R (color->go_color),
+			    GO_UINT_RGBA_G (color->go_color),
+			    GO_UINT_RGBA_B (color->go_color));
 	else
 		g_printerr ("\t%s: (NULL)\n", gnm_style_element_name [elem]);
 }
diff --git a/src/pattern.c b/src/pattern.c
index c558bb9..c3bc186 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -114,11 +114,13 @@ gnumeric_background_set_gtk (GnmStyle const *mstyle, cairo_t *context)
 #if 0
 			static double const true_grey[] = { 1.0, 1.0, .0625, .125, .25, .50, .75};
 #endif
+			GOColor c = back_col->go_color;
+			double f = grey[pattern];
 
 			cairo_set_source_rgb (context,
-				back_col->gdk_color.red * grey[pattern]    / (double) 0xffff,
-				back_col->gdk_color.green * grey[pattern]  / (double) 0xffff,
-				back_col->gdk_color.blue * grey[pattern]   / (double) 0xffff);
+					      GO_DOUBLE_RGBA_R (c) * f,
+					      GO_DOUBLE_RGBA_G (c) * f,
+					      GO_DOUBLE_RGBA_B (c) * f);
 		}
 
 		/* This is a special case where the user has selected
@@ -127,13 +129,14 @@ gnumeric_background_set_gtk (GnmStyle const *mstyle, cairo_t *context)
 		 */
 		if (pattern == 24) {
 			GnmColor const *pat_col = gnm_style_get_pattern_color (mstyle);
+			GOColor c;
 			g_return_val_if_fail (pat_col != NULL, FALSE);
 
+			c = pat_col->go_color;
 			cairo_set_source_rgb (context,
-				pat_col->gdk_color.red   / (double) 0xffff,
-				pat_col->gdk_color.green / (double) 0xffff,
-				pat_col->gdk_color.blue  / (double) 0xffff);
-
+					      GO_DOUBLE_RGBA_R (c),
+					      GO_DOUBLE_RGBA_G (c),
+					      GO_DOUBLE_RGBA_B (c));
 		}
 #if 0
 		/* FIXME: How to do the other patterns? */
diff --git a/src/sheet-control-gui.c b/src/sheet-control-gui.c
index 16f3a45..77344c1 100644
--- a/src/sheet-control-gui.c
+++ b/src/sheet-control-gui.c
@@ -1347,6 +1347,7 @@ sheet_control_gui_new (SheetView *sv, WBCGtk *wbcg)
 	GtkUpdateType scroll_update_policy;
 	Sheet *sheet;
 	GocDirection direction;
+	GdkColor cfore, cback;
 
 	g_return_val_if_fail (IS_SHEET_VIEW (sv), NULL);
 
@@ -1508,8 +1509,12 @@ sheet_control_gui_new (SheetView *sv, WBCGtk *wbcg)
 
 	scg->label = editable_label_new
 		(sheet->name_unquoted,
-		 sheet->tab_color ? &sheet->tab_color->gdk_color : NULL,
-		 sheet->tab_text_color ? &sheet->tab_text_color->gdk_color : NULL);
+		 sheet->tab_color
+		 ? go_color_to_gdk (sheet->tab_color->go_color, &cback)
+		 : NULL,
+		 sheet->tab_text_color
+		 ? go_color_to_gdk (sheet->tab_text_color->go_color, &cfore)
+		 : NULL);
 	g_object_ref (scg->label);
 
 	return scg;
diff --git a/src/style-border.c b/src/style-border.c
index 2ff22c9..f74b1da 100644
--- a/src/style-border.c
+++ b/src/style-border.c
@@ -113,7 +113,7 @@ style_border_equal (gconstpointer v1, gconstpointer v2)
 
 	/*
 	 * ->color is a pointer, but the comparison is safe because
-	 * all colours are cached, see style_color_new.
+	 * all colours are cached, see style_color_new_i16.
 	 */
 	return	(k1->color == k2->color) &&
 		(k1->line_type == k2->line_type);
@@ -128,7 +128,7 @@ style_border_hash (gconstpointer v)
 	 * HACK ALERT!
 	 *
 	 * ->color is a pointer, but the comparison is safe because
-	 * all colours are cached, see style_color_new.
+	 * all colours are cached, see style_color_new_i16.
 	 *
 	 */
 	return (GPOINTER_TO_UINT(b->color) ^ b->line_type);
@@ -181,7 +181,10 @@ gnm_style_border_none_set_color (GnmColor *color)
 	style_color_unref (nc);
 
 	if (none->gc) {
-		gdk_gc_set_rgb_fg_color (none->gc, &none->color->gdk_color);
+		GdkColor c;
+		gdk_gc_set_rgb_fg_color (none->gc,
+					 go_color_to_gdk (none->color->go_color,
+							  &c));
 	}
 }
 
@@ -560,9 +563,9 @@ style_border_set_gtk (GnmBorder const * const border,
 
 	gnm_style_border_set_dash (border->line_type, context);
 	cairo_set_source_rgb (context,
-			      border->color->gdk_color.red   / (double) 0xffff,
-			      border->color->gdk_color.green / (double) 0xffff,
-			      border->color->gdk_color.blue  / (double) 0xffff);
+			      GO_DOUBLE_RGBA_R (border->color->go_color),
+			      GO_DOUBLE_RGBA_G (border->color->go_color),
+			      GO_DOUBLE_RGBA_B (border->color->go_color));
 	return TRUE;
 }
 
diff --git a/src/style-color.c b/src/style-color.c
index a33b6f1..81b85cf 100644
--- a/src/style-color.c
+++ b/src/style-color.c
@@ -29,84 +29,70 @@ GnmColor *
 style_color_new_name (char const *name)
 {
 	GdkColor c;
-
 	gdk_color_parse (name, &c);
-	return style_color_new (c.red, c.green, c.blue);
+	return style_color_new_gdk (&c);
 }
 
 static GnmColor *
-style_color_new_uninterned (gushort red, gushort green, gushort blue,
-			    gboolean is_auto)
+style_color_new_uninterned (GOColor c, gboolean is_auto)
 {
 	GnmColor *sc = g_new (GnmColor, 1);
 
-	sc->gdk_color.red = red;
-	sc->gdk_color.green = green;
-	sc->gdk_color.blue = blue;
-	sc->gdk_color.pixel = gs_white.pixel;
-	sc->go_color = GO_RGBA_TO_UINT (red >> 8, green >> 8, blue >> 8, 0xff);
-	sc->is_auto = is_auto;
+	sc->go_color = c;
+	sc->is_auto = !!is_auto;
 	sc->ref_count = 1;
 
 	return sc;
 }
 
 GnmColor *
-style_color_new (gushort red, gushort green, gushort blue)
+style_color_new_i16 (gushort red, gushort green, gushort blue)
 {
-	GnmColor *sc;
-	GnmColor key;
-
-	key.gdk_color.red   = red;
-	key.gdk_color.green = green;
-	key.gdk_color.blue  = blue;
-	key.is_auto = FALSE;
-
-	sc = g_hash_table_lookup (style_color_hash, &key);
-	if (!sc) {
-		sc = style_color_new_uninterned (red, green, blue, FALSE);
-		g_hash_table_insert (style_color_hash, sc, sc);
-	} else
-		sc->ref_count++;
-
-	return sc;
+	return style_color_new_i8 (red >> 8, green >> 8, blue >> 8);
 }
 
 GnmColor *
 style_color_new_pango (PangoColor const *c)
 {
-	return style_color_new (c->red, c->green, c->blue);
+	return style_color_new_i16 (c->red, c->green, c->blue);
 }
+
 GnmColor *
 style_color_new_gdk (GdkColor const *c)
 {
-	return style_color_new (c->red, c->green, c->blue);
+	return style_color_new_i16 (c->red, c->green, c->blue);
 }
 
-/* scale 8 bit/color ->  16 bit/color by cloning */
 GnmColor *
 style_color_new_i8 (guint8 red, guint8 green, guint8 blue)
 {
-	gushort red16, green16, blue16;
-
-	red16 =   ((gushort) red) << 8   | red;
-	green16 = ((gushort) green) << 8 | green;
-	blue16 =  ((gushort) blue) << 8  | blue;
-
-	return style_color_new (red16, green16, blue16);
+	return style_color_new_go (GO_RGBA_TO_UINT (red, green, blue, 0xff));
 }
+
 GnmColor *
 style_color_new_go (GOColor c)
 {
-	return style_color_new_i8 (
-		GO_UINT_RGBA_R (c), GO_UINT_RGBA_G (c), GO_UINT_RGBA_B (c));
+	GnmColor *sc;
+	GnmColor key;
+
+	key.go_color = c;
+	key.is_auto = FALSE;
+
+	sc = g_hash_table_lookup (style_color_hash, &key);
+	if (!sc) {
+		sc = style_color_new_uninterned (c, FALSE);
+		g_hash_table_insert (style_color_hash, sc, sc);
+	} else
+		sc->ref_count++;
+
+	return sc;
 }
 
 GnmColor *
 style_color_black (void)
 {
 	if (!sc_black)
-		sc_black = style_color_new (0, 0, 0);
+		sc_black = style_color_new_i8 (0, 0, 0);
 	return style_color_ref (sc_black);
 }
 
@@ -114,7 +100,7 @@ GnmColor *
 style_color_white (void)
 {
 	if (!sc_white)
-		sc_white = style_color_new (0xffff, 0xffff, 0xffff);
+		sc_white = style_color_new_i8 (0xff, 0xff, 0xff);
 	return style_color_ref (sc_white);
 }
 
@@ -122,7 +108,7 @@ GnmColor *
 style_color_grid (void)
 {
 	if (!sc_grid)
-		sc_grid = style_color_new (0xc7c7, 0xc7c7, 0xc7c7);
+		sc_grid = style_color_new_i8 (0xc7, 0xc7, 0xc7);
 	return style_color_ref (sc_grid);
 }
 
@@ -139,7 +125,7 @@ style_color_auto_font (void)
 	static GnmColor *color = NULL;
 
 	if (!color)
-		color = style_color_new_uninterned (0, 0, 0, TRUE);
+		color = style_color_new_uninterned (GO_RGBA_BLACK, TRUE);
 	return style_color_ref (color);
 }
 
@@ -152,8 +138,7 @@ style_color_auto_back (void)
 	static GnmColor *color = NULL;
 
 	if (!color)
-		color = style_color_new_uninterned (0xffff, 0xffff, 0xffff,
-						    TRUE);
+		color = style_color_new_uninterned (GO_RGBA_WHITE, TRUE);
 	return style_color_ref (color);
 }
 
@@ -166,7 +151,7 @@ style_color_auto_pattern (void)
 	static GnmColor *color = NULL;
 
 	if (!color)
-		color = style_color_new_uninterned (0, 0, 0, TRUE);
+		color = style_color_new_uninterned (GO_RGBA_BLACK, TRUE);
 	return style_color_ref (color);
 }
 
@@ -191,10 +176,6 @@ style_color_unref (GnmColor *sc)
 	if (sc->ref_count != 0)
 		return;
 
-	/*
-	 * There is no need to deallocate colors, as they come from
-	 * the GDK Color Context
-	 */
 	g_hash_table_remove (style_color_hash, sc);
 	g_free (sc);
 }
@@ -202,22 +183,15 @@ style_color_unref (GnmColor *sc)
 gint
 style_color_equal (GnmColor const *k1, GnmColor const *k2)
 {
-	if (k1->gdk_color.red   == k2->gdk_color.red &&
-	    k1->gdk_color.green == k2->gdk_color.green &&
-	    k1->gdk_color.blue  == k2->gdk_color.blue &&
-	    k1->is_auto == k2->is_auto)
-		return 1;
-
-	return 0;
+	return (k1->go_color == k2->go_color &&
+		k1->is_auto == k2->is_auto);
 }
 
 static guint
 color_hash (gconstpointer v)
 {
 	GnmColor const *k = (GnmColor const *)v;
-
-	return (k->gdk_color.red << 16) ^ (k->gdk_color.green << 8) ^ (k->gdk_color.blue << 0) ^
-		(k->is_auto);
+	return k->go_color ^ k->is_auto;
 }
 
 void
@@ -225,12 +199,12 @@ gnm_color_init (void)
 {
 	GdkColor error;
 
-	gdk_color_parse ("cyan", &error);
 	if (gdk_screen_get_default () != NULL) {
 		/*
 		 * Make sure we can see bogus attempt at getting the pixel
 		 * value.  This is, by nature, not multi-head safe.
 		 */
+		gdk_color_parse ("cyan", &error);
 		gdk_rgb_find_color (
 			gdk_screen_get_default_colormap (
 				    gdk_screen_get_default ()),
@@ -240,13 +214,13 @@ gnm_color_init (void)
 
 	gs_black.pixel = error.pixel;
 	gs_white.pixel = error.pixel;
-	gs_yellow.pixel =  error.pixel;
-	gs_lavender.pixel =  error.pixel;
-	gs_dark_gray.pixel =  error.pixel;
-	gs_light_gray.pixel =  error.pixel;
+	gs_yellow.pixel = error.pixel;
+	gs_lavender.pixel = error.pixel;
+	gs_dark_gray.pixel = error.pixel;
+	gs_light_gray.pixel = error.pixel;
 
 	style_color_hash = g_hash_table_new (color_hash,
-					     (GEqualFunc) style_color_equal);
+					     (GEqualFunc)style_color_equal);
 }
 
 static void
@@ -254,11 +228,9 @@ cb_color_leak (gpointer key, gpointer value, gpointer user_data)
 {
 	GnmColor *color = value;
 
-	g_printerr ("Leaking style-color at %p [%04x:%04x:%04x].\n",
+	g_printerr ("Leaking style-color at %p [%08x].\n",
 		    (void *)color,
-		    color->gdk_color.red,
-		    color->gdk_color.green,
-		    color->gdk_color.blue);
+		    color->go_color);
 }
 
 void
diff --git a/src/style-color.h b/src/style-color.h
index db712a4..54c6f5c 100644
--- a/src/style-color.h
+++ b/src/style-color.h
@@ -13,7 +13,6 @@ G_BEGIN_DECLS
 GType gnm_style_color_get_type (void);
 
 struct _GnmColor {
-	GdkColor gdk_color;
 	GOColor	 go_color;
 	int      ref_count;
 	gboolean is_auto;
@@ -27,9 +26,9 @@ GNM_VAR_DECL GdkColor gs_black;
 GNM_VAR_DECL GdkColor gs_lavender;
 GNM_VAR_DECL GdkColor gs_yellow;
 
-GnmColor *style_color_new_go   (GOColor c);
+GnmColor *style_color_new_go    (GOColor c);
 GnmColor *style_color_new_name  (char const *name);
-GnmColor *style_color_new       (gushort red, gushort green, gushort blue);
+GnmColor *style_color_new_i16   (gushort red, gushort green, gushort blue);
 GnmColor *style_color_new_i8    (guint8 red, guint8 green, guint8 blue);
 GnmColor *style_color_new_pango (PangoColor const *c);
 GnmColor *style_color_new_gdk   (GdkColor const *c);
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index ad53a7b..5536c41 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -1090,14 +1090,20 @@ cb_sheet_tab_change (Sheet *sheet,
 		     G_GNUC_UNUSED GParamSpec *pspec,
 		     EditableLabel *el)
 {
+	GdkColor cfore, cback;
 	SheetControlGUI *scg = get_scg (GTK_WIDGET (el));
+
 	g_return_if_fail (IS_SHEET_CONTROL_GUI (scg));
 
 	/* We're lazy and just set all relevant attributes.  */
 	editable_label_set_text (el, sheet->name_unquoted);
 	editable_label_set_color (el,
-				  sheet->tab_color ? &sheet->tab_color->gdk_color : NULL,
-				  sheet->tab_text_color ? &sheet->tab_text_color->gdk_color : NULL);
+				  sheet->tab_color
+				  ? go_color_to_gdk (sheet->tab_color->go_color, &cback)
+				  : NULL,
+				  sheet->tab_text_color
+				  ? go_color_to_gdk (sheet->tab_text_color->go_color, &cfore)
+				  : NULL);
 
 	signal_paned_repartition (scg->wbcg->tabs_paned);
 }
@@ -2798,10 +2804,8 @@ cb_fore_color_changed (GOActionComboColor *a, WBCGtk *wbcg)
 	c = go_action_combo_color_get_color (a, &is_default);
 
 	if (wbcg_is_editing (wbcg)) {
-		GnmColor *color = style_color_new_go (is_default ? GO_RGBA_BLACK : c);
-		wbcg_edit_add_markup (wbcg, pango_attr_foreground_new (
-			color->gdk_color.red, color->gdk_color.green, color->gdk_color.blue));
-		style_color_unref (color);
+		GOColor c2 = is_default ? GO_RGBA_BLACK : c;
+		wbcg_edit_add_markup (wbcg, go_color_to_pango (c2, TRUE));
 		return;
 	}
 
@@ -2816,7 +2820,7 @@ static void
 wbc_gtk_init_color_fore (WBCGtk *gtk)
 {
 	GnmColor *sc_auto_font = style_color_auto_font ();
-	GOColor   default_color = GO_GDK_TO_UINT(sc_auto_font->gdk_color);
+	GOColor default_color = sc_auto_font->go_color;
 	style_color_unref (sc_auto_font);
 
 	gtk->fore_color = go_action_combo_color_new ("ColorFore", "font",
diff --git a/src/xml-io.c b/src/xml-io.c
index 4e2104e..db6aafb 100644
--- a/src/xml-io.c
+++ b/src/xml-io.c
@@ -150,9 +150,7 @@ gnm_xml_out_add_gocolor (GsfXMLOut *o, char const *id, GOColor c)
 void
 gnm_xml_out_add_color (GsfXMLOut *o, char const *id, GnmColor const *c)
 {
-	g_return_if_fail (c != NULL);
-	gsf_xml_out_add_color (o, id,
-		c->gdk_color.red, c->gdk_color.green, c->gdk_color.blue);
+	gnm_xml_out_add_gocolor (o, id, c->go_color);
 }
 
 void
@@ -206,7 +204,7 @@ xml_node_get_color (xmlNodePtr node, char const *name)
 	if (color == NULL)
 		return NULL;
 	if (sscanf (CXML2C (color), "%X:%X:%X", &red, &green, &blue) == 3)
-		res = style_color_new (red, green, blue);
+		res = style_color_new_i16 (red, green, blue);
 	xmlFree (color);
 	return res;
 }
@@ -214,9 +212,11 @@ xml_node_get_color (xmlNodePtr node, char const *name)
 void
 xml_node_set_color (xmlNodePtr node, char const *name, GnmColor const *val)
 {
-	char str[4 * sizeof (val->gdk_color)];
-	sprintf (str, "%X:%X:%X",
-		 val->gdk_color.red, val->gdk_color.green, val->gdk_color.blue);
+	GdkColor tmp;
+	char str[4 * sizeof (tmp)];
+
+	go_color_to_gdk (val->go_color, &tmp);
+	sprintf (str, "%X:%X:%X", tmp.red, tmp.green, tmp.blue);
 	go_xml_node_set_cstr (node, name, str);
 }
 
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index 0a0b840..b9305be 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -239,7 +239,7 @@ xml_sax_attr_color (xmlChar const * const *attrs, char const *name, GnmColor **r
 			   name, attrs[1]);
 		return FALSE;
 	}
-	*res = style_color_new (red, green, blue);
+	*res = style_color_new_i16 (red, green, blue);
 	return TRUE;
 }
 



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