/pidgin/main: c248c062f272: Pass the cairo context to the toolti...

Elliott Sales de Andrade qulogic at pidgin.im
Tue Jul 24 04:03:51 EDT 2012


Changeset: c248c062f2727607cb45a99bea284c981cbb239b
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2012-07-18 17:56 -0400
Branch:	 cpw.qulogic.gtk3-required
URL: http://hg.pidgin.im/pidgin/main/rev/c248c062f272

Description:

Pass the cairo context to the tooltip paint function.

This way, the paint function doesn't need to allocate another one
itself, which should save some (small) resources.

diffstat:

 pidgin/gtkblist.c      |  5 +----
 pidgin/gtkplugin.c     |  4 +---
 pidgin/gtkroomlist.c   |  4 +---
 pidgin/pidgintooltip.c |  2 +-
 pidgin/pidgintooltip.h |  4 +++-
 5 files changed, 7 insertions(+), 12 deletions(-)

diffs (108 lines):

diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -2950,10 +2950,9 @@
 }
 
 static gboolean
-pidgin_blist_paint_tip(GtkWidget *widget, gpointer null)
+pidgin_blist_paint_tip(GtkWidget *widget, cairo_t *cr, gpointer null)
 {
 	GtkStyle *style;
-	cairo_t *cr;
 	int current_height, max_width;
 	int max_text_width;
 	int max_avatar_width;
@@ -2987,7 +2986,6 @@
 	else
 		prpl_col = TOOLTIP_BORDER + status_size + SMALL_SPACE + max_text_width - PRPL_SIZE;
 
-	cr = gdk_cairo_create(gtk_widget_get_window(gtkblist->tipwindow));
 	current_height = 12;
 	for(l = gtkblist->tooltipdata; l; l = l->next)
 	{
@@ -3071,7 +3069,6 @@
 		current_height += MAX(td->name_height + td->height, td->avatar_height) + td->padding;
 	}
 
-	cairo_destroy(cr);
 	return FALSE;
 }
 
diff --git a/pidgin/gtkplugin.c b/pidgin/gtkplugin.c
--- a/pidgin/gtkplugin.c
+++ b/pidgin/gtkplugin.c
@@ -559,14 +559,12 @@
 }
 
 static gboolean
-pidgin_plugins_paint_tooltip(GtkWidget *tipwindow, gpointer data)
+pidgin_plugins_paint_tooltip(GtkWidget *tipwindow, cairo_t *cr, gpointer data)
 {
 	PangoLayout *layout = g_object_get_data(G_OBJECT(tipwindow), "tooltip-plugin");
-	cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(tipwindow));
 	gtk_paint_layout(gtk_widget_get_style(tipwindow), cr, GTK_STATE_NORMAL, FALSE,
 			tipwindow, "tooltip",
 			6, 6, layout);
-	cairo_destroy(cr);
 
 	return TRUE;
 }
diff --git a/pidgin/gtkroomlist.c b/pidgin/gtkroomlist.c
--- a/pidgin/gtkroomlist.c
+++ b/pidgin/gtkroomlist.c
@@ -352,7 +352,7 @@
 #define TOOLTIP_BORDER 12
 
 static gboolean
-pidgin_roomlist_paint_tooltip(GtkWidget *widget, gpointer user_data)
+pidgin_roomlist_paint_tooltip(GtkWidget *widget, cairo_t *cr, gpointer user_data)
 {
 	PurpleRoomlist *list = user_data;
 	PidginRoomlist *grl = purple_roomlist_get_ui_data(list);
@@ -360,7 +360,6 @@
 	int current_height, max_width;
 	int max_text_width;
 	GtkTextDirection dir = gtk_widget_get_direction(GTK_WIDGET(grl->tree));
-	cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(grl->tipwindow));
 
 	style = gtk_widget_get_style(grl->tipwindow);
 
@@ -390,7 +389,6 @@
 				current_height + grl->tip_name_height,
 				grl->tip_layout);
 	}
-	cairo_destroy(cr);
 
 	return FALSE;
 }
diff --git a/pidgin/pidgintooltip.c b/pidgin/pidgintooltip.c
--- a/pidgin/pidgintooltip.c
+++ b/pidgin/pidgintooltip.c
@@ -111,7 +111,7 @@
 		gtk_paint_flat_box(gtk_widget_get_style(widget), cr,
 			GTK_STATE_NORMAL, GTK_SHADOW_OUT,
 			widget, "tooltip", 0, 0, allocation.width, allocation.height);
-		pidgin_tooltip.paint_tooltip(widget, data);
+		pidgin_tooltip.paint_tooltip(widget, cr, data);
 	}
 	return FALSE;
 }
diff --git a/pidgin/pidgintooltip.h b/pidgin/pidgintooltip.h
--- a/pidgin/pidgintooltip.h
+++ b/pidgin/pidgintooltip.h
@@ -53,11 +53,13 @@
 
 /**
  * @param  tipwindow   The window for the tooltip.
+ * @param  cr          The cairo context for drawing.
  * @param  userdata    The userdata set during pidgin_tooltip_setup_for_treeview or pidgin_tooltip_show.
  *
  * @return  @c TRUE if the tooltip was painted correctly, @c FALSE otherwise.
  */
-typedef gboolean (*PidginTooltipPaint)(GtkWidget *tipwindow, gpointer userdata);
+typedef gboolean (*PidginTooltipPaint)(GtkWidget *tipwindow, cairo_t *cr,
+			gpointer userdata);
 
 G_BEGIN_DECLS
 



More information about the Commits mailing list