Replace GtkStyle with GtkStyleContext.

Sat, 03 Sep 2016 17:08:37 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sat, 03 Sep 2016 17:08:37 -0400
changeset 37996
6c9cb1e8b2d9
parent 37995
d5ab4262ea77
child 37997
7b62a2153898

Replace GtkStyle with GtkStyleContext.

Note that text_aa has been removed, so it's been replaced by manual
determination of the halfway point between foreground and background.
However, the background may no longer be a single colour, so we should
replace this with some sort of CSS-themed colour state.

pidgin/gtkstatusbox.c file | annotate | diff | comparison | revisions
pidgin/gtkutils.c file | annotate | diff | comparison | revisions
pidgin/gtkwebviewtoolbar.c file | annotate | diff | comparison | revisions
--- a/pidgin/gtkstatusbox.c	Sat Sep 03 16:03:29 2016 -0400
+++ b/pidgin/gtkstatusbox.c	Sat Sep 03 17:08:37 2016 -0400
@@ -597,8 +597,7 @@
 static void
 pidgin_status_box_refresh(PidginStatusBox *status_box)
 {
-	GtkStyle *style;
-	char aa_color[8];
+	const char *aa_color;
 	PurpleSavedStatus *saved_status;
 	char *primary, *secondary, *text;
 	const char *stock = NULL;
@@ -607,12 +606,6 @@
 	gboolean account_status = FALSE;
 	PurpleAccount *acct = (status_box->account) ? status_box->account : status_box->token_status_account;
 
-	style = gtk_widget_get_style(GTK_WIDGET(status_box));
-	snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x",
-		 style->text_aa[GTK_STATE_NORMAL].red >> 8,
-		 style->text_aa[GTK_STATE_NORMAL].green >> 8,
-		 style->text_aa[GTK_STATE_NORMAL].blue >> 8);
-
 	saved_status = purple_savedstatus_get_current();
 
 	if (status_box->account || (status_box->token_status_account
@@ -693,6 +686,7 @@
 		stock = pidgin_stock_id_from_status_primitive(prim);
 	}
 
+	aa_color = pidgin_get_dim_grey_string(GTK_WIDGET(status_box));
 	if (status_box->account != NULL) {
 		text = g_strdup_printf("%s - <span size=\"smaller\" color=\"%s\">%s</span>",
 				       purple_account_get_username(status_box->account),
@@ -2078,15 +2072,10 @@
 	}
 	else
 	{
-		GtkStyle *style;
-		char aa_color[8];
+		const char *aa_color;
 		gchar *escaped_title, *escaped_desc;
 
-		style = gtk_widget_get_style(GTK_WIDGET(status_box));
-		snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x",
-			 style->text_aa[GTK_STATE_NORMAL].red >> 8,
-			 style->text_aa[GTK_STATE_NORMAL].green >> 8,
-			 style->text_aa[GTK_STATE_NORMAL].blue >> 8);
+		aa_color = pidgin_get_dim_grey_string(GTK_WIDGET(status_box));
 
 		escaped_title = g_markup_escape_text(title, -1);
 		escaped_desc = g_markup_escape_text(desc, -1);
--- a/pidgin/gtkutils.c	Sat Sep 03 16:03:29 2016 -0400
+++ b/pidgin/gtkutils.c	Sat Sep 03 17:08:37 2016 -0400
@@ -1182,6 +1182,7 @@
 							gpointer data)
 {
 	GtkWidget *widget;
+	GtkStyleContext *context;
 	GtkRequisition requisition;
 	GdkScreen *screen;
 	GdkRectangle monitor;
@@ -1197,8 +1198,10 @@
 
 	widget     = GTK_WIDGET(menu);
 	screen     = gtk_widget_get_screen(widget);
-	xthickness = gtk_widget_get_style(widget)->xthickness;
-	ythickness = gtk_widget_get_style(widget)->ythickness;
+	context    = gtk_widget_get_style_context(widget);
+	gtk_style_context_get(context, gtk_style_context_get_state(context),
+	                      "xthickness", &xthickness,
+	                      "ythickness", &ythickness, NULL);
 	rtl        = (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL);
 
 	/*
@@ -1336,8 +1339,12 @@
 	GtkTreePath *path;
 	GtkTreeViewColumn *col;
 	GdkRectangle rect;
-	gint ythickness = gtk_widget_get_style(GTK_WIDGET(menu))->ythickness;
-
+	GtkStyleContext *context;
+	gint ythickness;
+
+	context = gtk_widget_get_style_context(GTK_WIDGET(menu));
+	gtk_style_context_get(context, gtk_style_context_get_state(context),
+	                      "ythickness", &ythickness, NULL);
 	gdk_window_get_origin (gtk_widget_get_window(widget), x, y);
 	gtk_tree_view_get_cursor (tv, &path, &col);
 	gtk_tree_view_get_cell_area (tv, path, col, &rect);
@@ -2793,19 +2800,25 @@
 
 const char *pidgin_get_dim_grey_string(GtkWidget *widget) {
 	static char dim_grey_string[8] = "";
-	GtkStyle *style;
+	GtkStyleContext *context;
+	GdkRGBA fg, bg;
 
 	if (!widget)
 		return "dim grey";
 
-	style = gtk_widget_get_style(widget);
-	if (!style)
+	context = gtk_widget_get_style_context(widget);
+	if (!context)
 		return "dim grey";
 
+	gtk_style_context_get_color(context, gtk_style_context_get_state(context),
+	                            &fg);
+	gtk_style_context_get_background_color(context,
+	                                       gtk_style_context_get_state(context),
+	                                       &bg);
 	snprintf(dim_grey_string, sizeof(dim_grey_string), "#%02x%02x%02x",
-	style->text_aa[GTK_STATE_NORMAL].red >> 8,
-	style->text_aa[GTK_STATE_NORMAL].green >> 8,
-	style->text_aa[GTK_STATE_NORMAL].blue >> 8);
+		 (unsigned int)((fg.red + bg.red) * 0.5 * 255),
+		 (unsigned int)((fg.green + bg.green) * 0.5 * 255),
+		 (unsigned int)((fg.blue + bg.blue) * 0.5 * 255));
 	return dim_grey_string;
 }
 
--- a/pidgin/gtkwebviewtoolbar.c	Sat Sep 03 16:03:29 2016 -0400
+++ b/pidgin/gtkwebviewtoolbar.c	Sat Sep 03 17:08:37 2016 -0400
@@ -1199,9 +1199,13 @@
 	GtkWidget *widget = GTK_WIDGET(data);
 	GtkRequisition menu_req;
 	GtkAllocation allocation;
-	gint ythickness = gtk_widget_get_style(widget)->ythickness;
+	GtkStyleContext *context;
+	gint ythickness;
 	int savy;
 
+	context = gtk_widget_get_style_context(widget);
+	gtk_style_context_get(context, gtk_style_context_get_state(context),
+	                      "ythickness", &ythickness, NULL);
 	gtk_widget_get_allocation(widget, &allocation);
 	gtk_widget_get_preferred_size(GTK_WIDGET(menu), NULL, &menu_req);
 	gdk_window_get_origin(gtk_widget_get_window(widget), x, y);

mercurial