[libegg] treeviewutils: Adapt to GTK+ 3 and newer GTK+ 2



commit 460c2d0d7b455edcbaa715f107092f525491d095
Author: David King <davidk openismus com>
Date:   Tue Apr 5 15:59:18 2011 +0200

    treeviewutils: Adapt to GTK+ 3 and newer GTK+ 2
    
    Adapt to new GtkCellRenderer render virtual function signature. Use
    single includes in EggTreeModelFilter (although it has already been
    included in GTK+ 2.4). Use accel_edited signal and
    gtk_dialog_get_content_area in test-tree-utils.

 libegg/treeviewutils/egg-cell-renderer-text.c |   63 +++++++++++++++++++++++++
 libegg/treeviewutils/eggtreemodelfilter.c     |    2 +-
 libegg/treeviewutils/test-tree-utils.c        |    5 +-
 3 files changed, 67 insertions(+), 3 deletions(-)
---
diff --git a/libegg/treeviewutils/egg-cell-renderer-text.c b/libegg/treeviewutils/egg-cell-renderer-text.c
index a0a8803..b47df36 100644
--- a/libegg/treeviewutils/egg-cell-renderer-text.c
+++ b/libegg/treeviewutils/egg-cell-renderer-text.c
@@ -22,6 +22,14 @@
 
 static void egg_cell_renderer_text_class_init    
                                    (EggCellRendererTextClass *cell_text_class);
+#if GTK_CHECK_VERSION (3,0,0)
+static void egg_cell_renderer_text_render (GtkCellRenderer     *cell,
+					   cairo_t             *cr,
+					   GtkWidget           *widget,
+					   const GdkRectangle  *background_area,
+					   const GdkRectangle  *cell_area,
+					   GtkCellRendererState flags);
+#else
 static void egg_cell_renderer_text_render     (GtkCellRenderer          *cell,
 					       GdkWindow                *window,
 					       GtkWidget                *widget,
@@ -29,6 +37,7 @@ static void egg_cell_renderer_text_render     (GtkCellRenderer          *cell,
 					       const GdkRectangle       *cell_area,
 					       const GdkRectangle       *expose_area,
 					       GtkCellRendererState      flags);
+#endif
 
 static GtkCellRendererTextClass *parent_class = NULL;
 
@@ -77,6 +86,59 @@ egg_cell_renderer_text_new (void)
   return GTK_CELL_RENDERER (g_object_new (EGG_TYPE_CELL_RENDERER_TEXT, NULL));
 }
 
+#if GTK_CHECK_VERSION (3,0,0)
+static void
+egg_cell_renderer_text_render (GtkCellRenderer     *cell,
+			       cairo_t             *cr,
+			       GtkWidget           *widget,
+			       const GdkRectangle  *background_area,
+			       const GdkRectangle  *cell_area,
+			       GtkCellRendererState flags)
+{
+	GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
+	GtkStateType state;
+	gboolean background_set;
+
+	if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
+	{
+		if (gtk_widget_has_focus (widget))
+			state = GTK_STATE_SELECTED;
+		else
+			state = GTK_STATE_ACTIVE;
+	}
+	else
+	{
+		if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
+			state = GTK_STATE_INSENSITIVE;
+		else
+			state = GTK_STATE_NORMAL;
+	}
+
+	g_object_get (celltext, "cell-background-set", &background_set, NULL);
+	if (state == GTK_STATE_SELECTED && background_set)
+	{
+		GdkRGBA color;
+		guint ypad;
+
+		g_object_get (celltext, "cell-background-rgba", &color,
+		                        "ypad", &ypad, NULL);
+
+		gdk_cairo_set_source_rgba (cr, &color);
+
+		cairo_rectangle (cr,
+		                 background_area->x,
+				 background_area->y + ypad,
+				 background_area->width,
+				 background_area->height - 2 * ypad);
+
+		cairo_fill (cr);
+	}
+
+	GTK_CELL_RENDERER_CLASS (parent_class)->render (cell, cr, widget,
+							background_area,
+							cell_area, flags);
+}
+#else /* !GTK_CHECK_VERSION (3,0,0) */
 static void
 egg_cell_renderer_text_render (GtkCellRenderer     *cell,
 			       GdkWindow           *window,
@@ -141,3 +203,4 @@ egg_cell_renderer_text_render (GtkCellRenderer     *cell,
 	GTK_CELL_RENDERER_CLASS (parent_class)->render (cell, window, widget, background_area,
 			       cell_area, expose_area, flags);
 }
+#endif /* GTK_CHECK_VERSION (3,0,0) */
diff --git a/libegg/treeviewutils/eggtreemodelfilter.c b/libegg/treeviewutils/eggtreemodelfilter.c
index 152df25..ecd2de7 100644
--- a/libegg/treeviewutils/eggtreemodelfilter.c
+++ b/libegg/treeviewutils/eggtreemodelfilter.c
@@ -23,7 +23,7 @@
 #endif
 
 #include "eggtreemodelfilter.h"
-#include <gtk/gtksignal.h>
+#include <gtk/gtk.h>
 #include <string.h>
 
 /* FIXME: remove this when we move it to GTK+ */
diff --git a/libegg/treeviewutils/test-tree-utils.c b/libegg/treeviewutils/test-tree-utils.c
index ab2a577..596121c 100644
--- a/libegg/treeviewutils/test-tree-utils.c
+++ b/libegg/treeviewutils/test-tree-utils.c
@@ -219,7 +219,7 @@ key_test (void)
 	rend = egg_cell_renderer_keys_new ();
 	g_object_set (G_OBJECT (rend), "accel_mode", EGG_CELL_RENDERER_KEYS_MODE_X, NULL);
 	g_signal_connect (G_OBJECT (rend),
-			  "keys_edited",
+			  "accel_edited",
 			  G_CALLBACK (accel_edited_callback),
 			  store);
 
@@ -311,7 +311,8 @@ main (gint argc, gchar **argv)
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
 				  GTK_POLICY_AUTOMATIC,
 				  GTK_POLICY_AUTOMATIC);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), sw, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+		      sw, TRUE, TRUE, 0);
 
   model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
 



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