[Commits] [SCM] claws branch, master, updated. 4.1.0-42-gcfecbde13

mones at claws-mail.org mones at claws-mail.org
Wed Jul 20 14:47:20 UTC 2022


The branch, master has been updated
       via  cfecbde1396e473af1b9567e91e823b1ad566b46 (commit)
      from  a7993f658188621baf2f59b1b039f6c528067676 (commit)

Summary of changes:
 src/printing.c | 85 +++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 58 insertions(+), 27 deletions(-)


- Log -----------------------------------------------------------------
commit cfecbde1396e473af1b9567e91e823b1ad566b46
Author: Ricardo Mones <ricardo at mones.org>
Date:   Wed Jul 20 16:46:58 2022 +0200

    Remove GTK3 deprecated calls from printing
    
    Fixes:
    sys:1: Warning: ../../../gobject/gsignal.c:2613: signal 'expose_event'
    is invalid for instance '0x2d768d0' of type 'GtkDrawingArea'
    
    And the following warnings are also gone:
    • printing.c:517:9: warning: ‘gtk_widget_set_double_buffered’ is deprecated
    • printing.c:648:9: warning: ‘gdk_cairo_create’ is deprecated: …
    • printing.c:1262:65: warning: ‘gdk_color_free’ is deprecated: …

diff --git a/src/printing.c b/src/printing.c
index 144b6f5a9..86a9faf9e 100644
--- a/src/printing.c
+++ b/src/printing.c
@@ -93,7 +93,7 @@ static gboolean cb_preview_close(GtkWidget*, GdkEventAny*, gpointer);
 static void     cb_preview_size_allocate(GtkWidget*, GtkAllocation*);
 static void     cb_preview_ready(GtkPrintOperationPreview*,
 				 GtkPrintContext*, gpointer);
-static gboolean cb_preview_expose(GtkWidget*, GdkEventExpose*, gpointer);
+static gboolean cb_drawing_area(GtkWidget *widget, cairo_t *cr, gpointer data);
 static void     cb_preview_got_page_size(GtkPrintOperationPreview*,
 					 GtkPrintContext*,
 					 GtkPageSetup*, gpointer);
@@ -118,7 +118,8 @@ static GtkPageSetup     *page_setup = NULL;
 
 /* other static functions */
 static void     printing_layout_set_text_attributes(PrintData*, GtkPrintContext *, gboolean *);
-static gboolean printing_is_pango_gdk_color_equal(PangoColor*, GdkColor*); 
+static gboolean printing_is_pango_gdk_rgba_equal(PangoColor*, GdkRGBA*);
+PangoColor*     printing_pango_color_from_gdk_rgba(GdkRGBA*);
 static gint     printing_text_iter_get_offset_bytes(PrintData *, const GtkTextIter*);
 
 #define PAGE_MARGIN_STORAGE_UNIT GTK_UNIT_MM
@@ -395,7 +396,9 @@ static gboolean cb_preview(GtkPrintOperation        *operation,
 			   gpointer                 data)
 {
 	PrintData *print_data;
+	cairo_region_t *creg;
 	cairo_t *cr;
+	GdkDrawingContext *gdc;
 	PreviewData *preview_data;
 	GtkWidget *vbox;
 	GtkWidget *toolbar;
@@ -514,16 +517,18 @@ static gboolean cb_preview(GtkPrintOperation        *operation,
 				       GTK_POLICY_AUTOMATIC);
 	gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
 	da = gtk_drawing_area_new();
-	gtk_widget_set_double_buffered(da, FALSE);
 	gtk_container_add(GTK_CONTAINER(sw), da);
 	gtk_widget_realize(da);
 	preview_data->scrolled_window = sw;
 	preview_data->area = da;
 
 	/* cairo context */
-	cr = gdk_cairo_create(gtk_widget_get_window(da));
+	creg = cairo_region_create();
+	gdc = gdk_window_begin_draw_frame(gtk_widget_get_window(da), creg);
+	cr = gdk_drawing_context_get_cairo_context(gdc);
 	gtk_print_context_set_cairo_context(context, cr, PREVIEW_SCALE, PREVIEW_SCALE);
-	cairo_destroy(cr);
+	gdk_window_end_draw_frame(gtk_widget_get_window(da), gdc);
+	cairo_region_destroy(creg);
 
 	/* signals */
 	g_signal_connect(dialog, "key_press_event",
@@ -604,9 +609,8 @@ static void cb_preview_ready(GtkPrintOperationPreview *preview,
 	preview_data->current_page = preview_data->pages_to_print;
 	preview_data->context = context;
 
-	g_signal_connect(preview_data->area, "expose_event",
-			 G_CALLBACK(cb_preview_expose),
-			 preview_data);
+	g_signal_connect(G_OBJECT (preview_data->area), "draw",
+					 G_CALLBACK(cb_drawing_area), preview_data);
 
 	gtk_widget_queue_draw(preview_data->area);
 }
@@ -637,19 +641,25 @@ static void cb_preview_got_page_size(GtkPrintOperationPreview *preview,
 				    paper_width, paper_height);
 }
 
-static gboolean cb_preview_expose(GtkWidget *widget, GdkEventExpose *event,
-				  gpointer data)
+static gboolean cb_drawing_area(GtkWidget *widget, cairo_t *cr, gpointer data)
 {
 	PreviewData *preview_data = data;
-	cairo_t *cr;
+	GdkDrawingContext *gdc;
+	cairo_region_t *creg;
+	guint width, height;
+
+	width = gtk_widget_get_allocated_width (widget);
+	height = gtk_widget_get_allocated_height (widget);
 
 	debug_print("preview_expose (current %p)\n", preview_data->current_page);
 
-	cr = gdk_cairo_create(gtk_widget_get_window(preview_data->area));
+	creg = cairo_region_create();
+	gdc = gdk_window_begin_draw_frame(gtk_widget_get_window(preview_data->area), creg);
+	cr = gdk_drawing_context_get_cairo_context(gdc);
 
 	/* background */
 	cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
-	cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height);
+	cairo_rectangle(cr, 0, 0, width, height);
 	cairo_fill(cr);
 
 	/* shadow */
@@ -667,7 +677,8 @@ static gboolean cb_preview_expose(GtkWidget *widget, GdkEventExpose *event,
 	cairo_fill(cr);
 
 	gtk_print_context_set_cairo_context(preview_data->context, cr, PREVIEW_SCALE, PREVIEW_SCALE);
-	cairo_destroy(cr);
+	gdk_window_end_draw_frame(gtk_widget_get_window(preview_data->area), gdc);
+	cairo_region_destroy(creg);
 
 	if (preview_data->current_page) {
 		preview_data->rendering = TRUE;
@@ -1166,7 +1177,7 @@ static void printing_layout_set_text_attributes(PrintData *print_data,
 		gboolean fg_set, bg_set, under_set, strike_set, weight_set;
 		GSList *tags, *tag_walk;
 		GtkTextTag *tag;
-		GdkColor *color = NULL;
+		GdkRGBA *color = NULL;
 		PangoUnderline underline;
 		gboolean strikethrough;
 		gint weight;
@@ -1221,10 +1232,10 @@ static void printing_layout_set_text_attributes(PrintData *print_data,
 						attr = (PangoAttribute*)attr_walk->data;
 						if (attr->klass->type == PANGO_ATTR_FOREGROUND) {
 							attr_color = (PangoAttrColor*) attr;
-							g_object_get(G_OBJECT(tag), "foreground_gdk",
+							g_object_get(G_OBJECT(tag), "foreground-rgba",
 								     &color, NULL);
 							if (color && 
-							    printing_is_pango_gdk_color_equal(&(attr_color->color),
+							    printing_is_pango_gdk_rgba_equal(&(attr_color->color),
 							    color)) {
 								attr->end_index = printing_text_iter_get_offset_bytes(print_data, &iter);
 								pango_attr_list_insert(attr_list, attr);
@@ -1233,7 +1244,7 @@ static void printing_layout_set_text_attributes(PrintData *print_data,
 								break;
 							}
 							if (color)
-								gdk_color_free(color);
+								gdk_rgba_free(color);
 						}
 					}
 					if (!found)
@@ -1247,10 +1258,10 @@ static void printing_layout_set_text_attributes(PrintData *print_data,
 						attr = (PangoAttribute*)attr_walk->data;
 						if (attr->klass->type == PANGO_ATTR_BACKGROUND) {
 							attr_color = (PangoAttrColor*) attr;
-							g_object_get(G_OBJECT(tag), "background-gdk",
+							g_object_get(G_OBJECT(tag), "background-rgba",
 								     &color, NULL);
 							if (color && 
-							    printing_is_pango_gdk_color_equal(&(attr_color->color),
+							    printing_is_pango_gdk_rgba_equal(&(attr_color->color),
 							    color)) {
 								attr->end_index = printing_text_iter_get_offset_bytes(print_data, &iter);
 								pango_attr_list_insert(attr_list, attr);
@@ -1259,7 +1270,7 @@ static void printing_layout_set_text_attributes(PrintData *print_data,
 								break;
 							}
 							if (color)
-								gdk_color_free(color);
+								gdk_rgba_free(color);
 	    					}
 					}
 					if (!found)
@@ -1349,16 +1360,20 @@ static void printing_layout_set_text_attributes(PrintData *print_data,
 					     "weight-set", &weight_set,
 					     NULL);
 				if (fg_set) {
-					g_object_get(G_OBJECT(tag), "foreground-gdk", &color, NULL);
-					attr = pango_attr_foreground_new(color->red,color->green,color->blue);
+					g_object_get(G_OBJECT(tag), "foreground-rgba", &color, NULL);
+					PangoColor *pc = printing_pango_color_from_gdk_rgba(color);
+					attr = pango_attr_foreground_new(pc->red, pc->green, pc->blue);
 					attr->start_index = printing_text_iter_get_offset_bytes(print_data, &iter);
 					open_attrs = g_slist_prepend(open_attrs, attr);
+					g_free(pc);
 				}
 				if (bg_set) {
-					g_object_get(G_OBJECT(tag), "background-gdk", &color, NULL);
-					attr = pango_attr_background_new(color->red,color->green,color->blue);
+					g_object_get(G_OBJECT(tag), "background-rgba", &color, NULL);
+					PangoColor *pc = printing_pango_color_from_gdk_rgba(color);
+					attr = pango_attr_background_new(pc->red, pc->green, pc->blue);
 					attr->start_index = printing_text_iter_get_offset_bytes(print_data, &iter);
 					open_attrs = g_slist_prepend(open_attrs, attr);
+					g_free(pc);
 				}
 				if (under_set) {
 					g_object_get(G_OBJECT(tag), "underline", &underline, NULL);
@@ -1401,9 +1416,25 @@ static void printing_layout_set_text_attributes(PrintData *print_data,
 	pango_attr_list_unref(attr_list);
 }
 
-static gboolean printing_is_pango_gdk_color_equal(PangoColor *p, GdkColor *g)
+PangoColor* printing_pango_color_from_gdk_rgba(GdkRGBA* g)
+{
+	PangoColor *c;
+
+	c = g_new(PangoColor, 1);
+	c->red = (guint16) (g->red * 65535);
+	c->green = (guint16) (g->green * 65535);
+	c->blue = (guint16) (g->blue * 65535);
+	return c;
+}
+
+static gboolean printing_is_pango_gdk_rgba_equal(PangoColor *p, GdkRGBA *g)
 {
-	return ((p->red == g->red) && (p->green == g->green) && (p->blue == g->blue));
+	PangoColor c;
+
+	c.red = (guint16) (g->red * 65535);
+	c.green = (guint16) (g->green * 65535);
+	c.blue = (guint16) (g->blue * 65535);
+	return ((c.red == p->red) && (c.green == p->green) && (c.blue == p->blue));
 }
 
 /* Pango has it's attribute in bytes, but GtkTextIter gets only an offset

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list