/pidgin/main: 73e1a4f7a1a9: Privatize some GtkWhiteboard fields.

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


Changeset: 73e1a4f7a1a960b804c4131df58f59f80c2c8755
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2012-07-23 02:06 -0400
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/73e1a4f7a1a9

Description:

Privatize some GtkWhiteboard fields.

I could probably hide more of these fields, but I'm lazy.

diffstat:

 pidgin/gtkwhiteboard.c |  59 ++++++++++++++++++++++++++-----------------------
 pidgin/gtkwhiteboard.h |  21 +++++++++++------
 2 files changed, 44 insertions(+), 36 deletions(-)

diffs (206 lines):

diff --git a/pidgin/gtkwhiteboard.c b/pidgin/gtkwhiteboard.c
--- a/pidgin/gtkwhiteboard.c
+++ b/pidgin/gtkwhiteboard.c
@@ -28,6 +28,11 @@
 #include "gtkwhiteboard.h"
 #include "gtkutils.h"
 
+struct _PidginWhiteboardPrivate {
+	GdkPixmap *pixmap;
+	cairo_t   *cr;
+};
+
 /******************************************************************************
  * Prototypes
  *****************************************************************************/
@@ -123,6 +128,7 @@
 	GtkWidget *color_button;
 
 	PidginWhiteboard *gtkwb = g_new0(PidginWhiteboard, 1);
+	gtkwb->priv = g_new0(PidginWhiteboardPrivate, 1);
 
 	gtkwb->wb = wb;
 	purple_whiteboard_set_ui_data(wb, gtkwb);
@@ -280,13 +286,11 @@
 	/* TODO Ask if user wants to save picture before the session is closed */
 
 	/* Clear graphical memory */
-	if(gtkwb->pixmap)
-	{
-		cairo_t *cr = g_object_get_data(G_OBJECT(gtkwb->pixmap), "cairo-context");
+	if (gtkwb->priv->pixmap) {
+		cairo_t *cr = gtkwb->priv->cr;
 		if (cr)
 			cairo_destroy(cr);
-		g_object_unref(gtkwb->pixmap);
-		gtkwb->pixmap = NULL;
+		g_object_unref(gtkwb->priv->pixmap);
 	}
 
 	colour_dialog = g_object_get_data(G_OBJECT(gtkwb->window), "colour-dialog");
@@ -300,6 +304,8 @@
 		gtk_widget_destroy(gtkwb->window);
 		gtkwb->window = NULL;
 	}
+
+	g_free(gtkwb->priv);
 	g_free(gtkwb);
 	purple_whiteboard_set_ui_data(wb, NULL);
 }
@@ -356,11 +362,11 @@
 static gboolean pidgin_whiteboard_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
 {
 	PidginWhiteboard *gtkwb = (PidginWhiteboard*)data;
-	GdkPixmap *pixmap = gtkwb->pixmap;
+	GdkPixmap *pixmap = gtkwb->priv->pixmap;
 	cairo_t *cr;
 
 	if (pixmap) {
-		cr = g_object_get_data(G_OBJECT(pixmap), "cairo-context");
+		cr = gtkwb->priv->cr;
 		if (cr)
 			cairo_destroy(cr);
 		g_object_unref(pixmap);
@@ -370,10 +376,10 @@
 							widget->allocation.width,
 							widget->allocation.height,
 							-1);
-	gtkwb->pixmap = pixmap;
+	gtkwb->priv->pixmap = pixmap;
 
 	cr = gdk_cairo_create(GDK_DRAWABLE(pixmap));
-	g_object_set_data(G_OBJECT(pixmap), "cairo-context", cr);
+	gtkwb->priv->cr = cr;
 	gdk_cairo_set_source_color(cr, &widget->style->white);
 	cairo_rectangle(cr,
 	                0, 0,
@@ -386,7 +392,7 @@
 static gboolean pidgin_whiteboard_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
 {
 	PidginWhiteboard *gtkwb = (PidginWhiteboard*)(data);
-	GdkPixmap *pixmap = gtkwb->pixmap;
+	GdkPixmap *pixmap = gtkwb->priv->pixmap;
 	cairo_t *cr;
 
 	cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
@@ -403,7 +409,7 @@
 static gboolean pidgin_whiteboard_brush_down(GtkWidget *widget, GdkEventButton *event, gpointer data)
 {
 	PidginWhiteboard *gtkwb = (PidginWhiteboard*)data;
-	GdkPixmap *pixmap = gtkwb->pixmap;
+	GdkPixmap *pixmap = gtkwb->priv->pixmap;
 
 	PurpleWhiteboard *wb = gtkwb->wb;
 	GList *draw_list = purple_whiteboard_get_draw_list(wb);
@@ -456,7 +462,7 @@
 	GdkModifierType state;
 
 	PidginWhiteboard *gtkwb = (PidginWhiteboard*)data;
-	GdkPixmap *pixmap = gtkwb->pixmap;
+	GdkPixmap *pixmap = gtkwb->priv->pixmap;
 
 	PurpleWhiteboard *wb = gtkwb->wb;
 	GList *draw_list = purple_whiteboard_get_draw_list(wb);
@@ -536,7 +542,7 @@
 static gboolean pidgin_whiteboard_brush_up(GtkWidget *widget, GdkEventButton *event, gpointer data)
 {
 	PidginWhiteboard *gtkwb = (PidginWhiteboard*)data;
-	GdkPixmap *pixmap = gtkwb->pixmap;
+	GdkPixmap *pixmap = gtkwb->priv->pixmap;
 
 	PurpleWhiteboard *wb = gtkwb->wb;
 	GList *draw_list = purple_whiteboard_get_draw_list(wb);
@@ -593,9 +599,7 @@
 {
 	PidginWhiteboard *gtkwb = purple_whiteboard_get_ui_data(wb);
 	GtkWidget *widget = gtkwb->drawing_area;
-	GdkPixmap *pixmap = gtkwb->pixmap;
-
-	cairo_t *gfx_con = g_object_get_data(G_OBJECT(pixmap), "cairo-context");
+	cairo_t *gfx_con = gtkwb->priv->cr;
 	GdkColor col;
 
 	/* Interpret and convert color */
@@ -701,9 +705,8 @@
 static void pidgin_whiteboard_clear(PurpleWhiteboard *wb)
 {
 	PidginWhiteboard *gtkwb = purple_whiteboard_get_ui_data(wb);
-	GdkPixmap *pixmap = gtkwb->pixmap;
 	GtkWidget *drawing_area = gtkwb->drawing_area;
-	cairo_t *cr = g_object_get_data(G_OBJECT(pixmap), "cairo-context");
+	cairo_t *cr = gtkwb->priv->cr;
 
 	gdk_cairo_set_source_color(cr, &drawing_area->style->white);
 	cairo_rectangle(cr,
@@ -782,11 +785,11 @@
 
 		/* Makes an icon from the whiteboard's canvas 'image' */
 		pixbuf = gdk_pixbuf_get_from_drawable(NULL,
-											  (GdkDrawable*)(gtkwb->pixmap),
-											  gdk_drawable_get_colormap(gtkwb->pixmap),
-											  0, 0,
-											  0, 0,
-											  gtkwb->width, gtkwb->height);
+		                                      (GdkDrawable*)(gtkwb->priv->pixmap),
+		                                      gdk_drawable_get_colormap(gtkwb->priv->pixmap),
+		                                      0, 0,
+		                                      0, 0,
+		                                      gtkwb->width, gtkwb->height);
 
 		if(gdk_pixbuf_save(pixbuf, filename, "jpeg", NULL, "quality", "100", NULL))
 			purple_debug_info("gtkwhiteboard", "File Saved...\n");
@@ -808,11 +811,11 @@
 
 	/* Makes an icon from the whiteboard's canvas 'image' */
 	pixbuf = gdk_pixbuf_get_from_drawable(NULL,
-										  (GdkDrawable*)(gtkwb->pixmap),
-										  gdk_drawable_get_colormap(gtkwb->pixmap),
-										  0, 0,
-										  0, 0,
-										  gtkwb->width, gtkwb->height);
+	                                      (GdkDrawable*)(gtkwb->priv->pixmap),
+	                                      gdk_drawable_get_colormap(gtkwb->priv->pixmap),
+	                                      0, 0,
+	                                      0, 0,
+	                                      gtkwb->width, gtkwb->height);
 
 	gtk_window_set_icon((GtkWindow*)(gtkwb->window), pixbuf);
 }
diff --git a/pidgin/gtkwhiteboard.h b/pidgin/gtkwhiteboard.h
--- a/pidgin/gtkwhiteboard.h
+++ b/pidgin/gtkwhiteboard.h
@@ -42,21 +42,26 @@
 #define PALETTE_NUM_COLORS  7
 
 /**
+ * A PidginWhiteboard's private data
+ */
+typedef struct _PidginWhiteboardPrivate PidginWhiteboardPrivate;
+
+/**
  * A PidginWhiteboard
  */
 typedef struct _PidginWhiteboard
 {
-	PurpleWhiteboard *wb;      /**< backend data for this whiteboard */
+	PidginWhiteboardPrivate *priv;  /**< Internal data */
 
-	GtkWidget *window;       /**< Window for the Doodle session */
-	GtkWidget *drawing_area; /**< Drawing area */
+	PurpleWhiteboard *wb;           /**< Backend data for this whiteboard */
 
-	GdkPixmap *pixmap;       /**< Memory for drawing area */
+	GtkWidget *window;              /**< Window for the Doodle session */
+	GtkWidget *drawing_area;        /**< Drawing area */
 
-	int  width;              /**< Canvas width */
-	int  height;             /**< Canvas height */
-	int brush_color;         /**< Foreground color */
-	int brush_size;          /**< Brush size */
+	int width;                      /**< Canvas width */
+	int height;                     /**< Canvas height */
+	int brush_color;                /**< Foreground color */
+	int brush_size;                 /**< Brush size */
 } PidginWhiteboard;
 
 G_BEGIN_DECLS



More information about the Commits mailing list