[libslab] Use G_DEFINE_TYPE where possible



commit e0a8cea58b187cfd6b1c2d73bd28d38b4fb6ad78
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Jun 30 20:16:57 2009 +0200

    Use G_DEFINE_TYPE where possible

 libslab/app-resizer.c           |   41 ++++++--------------------------------
 libslab/double-click-detector.c |   39 +------------------------------------
 libslab/shell-window.c          |   36 +---------------------------------
 3 files changed, 9 insertions(+), 107 deletions(-)
---
diff --git a/libslab/app-resizer.c b/libslab/app-resizer.c
index 44f7b02..118406d 100644
--- a/libslab/app-resizer.c
+++ b/libslab/app-resizer.c
@@ -24,8 +24,6 @@
 #include "app-shell.h"
 #include "app-resizer.h"
 
-static GtkLayoutClass *parent_class = NULL;
-
 static void app_resizer_class_init (AppResizerClass *);
 static void app_resizer_init (AppResizer *);
 static void app_resizer_destroy (GtkObject *);
@@ -34,39 +32,14 @@ static void app_resizer_size_allocate (GtkWidget * resizer, GtkAllocation * allo
 static gboolean app_resizer_paint_window (GtkWidget * widget, GdkEventExpose * event,
 	AppShellData * app_data);
 
-GType
-app_resizer_get_type (void)
-{
-	static GType object_type = 0;
+G_DEFINE_TYPE (AppResizer, app_resizer, GTK_TYPE_LAYOUT);
 
-	if (!object_type)
-	{
-		static const GTypeInfo object_info = {
-			sizeof (AppResizerClass),
-			NULL,
-			NULL,
-			(GClassInitFunc) app_resizer_class_init,
-			NULL,
-			NULL,
-			sizeof (AppResizer),
-			0,
-			(GInstanceInitFunc) app_resizer_init
-		};
-
-		object_type =
-			g_type_register_static (GTK_TYPE_LAYOUT, "AppResizer", &object_info, 0);
-	}
-
-	return object_type;
-}
 
 static void
 app_resizer_class_init (AppResizerClass * klass)
 {
 	GtkWidgetClass *widget_class;
 
-	parent_class = g_type_class_peek_parent (klass);
-
 	((GtkObjectClass *) klass)->destroy = app_resizer_destroy;
 
 	widget_class = GTK_WIDGET_CLASS (klass);
@@ -225,8 +198,8 @@ app_resizer_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
 	if (first_time)
 	{
 		/* we are letting the first show be the "natural" size of the child widget so do nothing. */
-		if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
-			(*GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
+		if (GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate)
+			(*GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (widget, allocation);
 
 		first_time = FALSE;
 		gtk_layout_set_size (GTK_LAYOUT (resizer), child->allocation.width,
@@ -238,8 +211,8 @@ app_resizer_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
 	{
 		GtkAllocation child_allocation;
 
-		if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
-			(*GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
+		if (GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate)
+			(*GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (widget, allocation);
 
 		/* We want the message to center itself and only scroll if it's bigger than the available real size. */
 		child_allocation.x = 0;
@@ -268,8 +241,8 @@ app_resizer_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
 		resizer->cur_num_cols = new_num_cols;
 	}
 
-	if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
-		(*GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
+	if (GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate)
+		(*GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (widget, allocation);
 	gtk_layout_set_size (GTK_LAYOUT (resizer), child->allocation.width,
 		child->allocation.height);
 }
diff --git a/libslab/double-click-detector.c b/libslab/double-click-detector.c
index df77351..64ed58e 100644
--- a/libslab/double-click-detector.c
+++ b/libslab/double-click-detector.c
@@ -24,43 +24,11 @@
 
 #include "libslab-utils.h"
 
-static void double_click_detector_class_init (DoubleClickDetectorClass *);
-static void double_click_detector_init (DoubleClickDetector *);
-static void double_click_detector_dispose (GObject *);
-
-GType
-double_click_detector_get_type (void)
-{
-	static GType object_type = 0;
-
-	if (!object_type)
-	{
-		static const GTypeInfo object_info = {
-			sizeof (DoubleClickDetectorClass),
-			NULL,
-			NULL,
-			(GClassInitFunc) double_click_detector_class_init,
-			NULL,
-			NULL,
-			sizeof (DoubleClickDetector),
-			0,
-			(GInstanceInitFunc) double_click_detector_init
-		};
-
-		object_type =
-			g_type_register_static (G_TYPE_OBJECT, "DoubleClickDetector", &object_info,
-			0);
-	}
-
-	return object_type;
-}
+G_DEFINE_TYPE (DoubleClickDetector, double_click_detector, G_TYPE_OBJECT);
 
 static void
 double_click_detector_class_init (DoubleClickDetectorClass * detector_class)
 {
-	GObjectClass *g_obj_class = (GObjectClass *) detector_class;
-
-	g_obj_class->dispose = double_click_detector_dispose;
 }
 
 static void
@@ -83,11 +51,6 @@ double_click_detector_new ()
 	return g_object_new (DOUBLE_CLICK_DETECTOR_TYPE, NULL);
 }
 
-static void
-double_click_detector_dispose (GObject * obj)
-{
-}
-
 gboolean
 double_click_detector_is_double_click (DoubleClickDetector *this, guint32 event_time,
                                        gboolean auto_update)
diff --git a/libslab/shell-window.c b/libslab/shell-window.c
index d7fd6d1..5202229 100644
--- a/libslab/shell-window.c
+++ b/libslab/shell-window.c
@@ -24,8 +24,6 @@
 
 #include "app-resizer.h"
 
-static GtkWindowClass *parent_class = NULL;
-
 static void shell_window_class_init (ShellWindowClass *);
 static void shell_window_init (ShellWindow *);
 static void shell_window_destroy (GtkObject *);
@@ -36,38 +34,11 @@ gboolean shell_window_paint_window (GtkWidget * widget, GdkEventExpose * event,
 
 #define SHELL_WINDOW_BORDER_WIDTH 6
 
-GType
-shell_window_get_type (void)
-{
-	static GType object_type = 0;
-
-	if (!object_type)
-	{
-		static const GTypeInfo object_info = {
-			sizeof (ShellWindowClass),
-			NULL,
-			NULL,
-			(GClassInitFunc) shell_window_class_init,
-			NULL,
-			NULL,
-			sizeof (ShellWindow),
-			0,
-			(GInstanceInitFunc) shell_window_init
-		};
-
-		object_type = g_type_register_static (
-			GTK_TYPE_FRAME, "ShellWindow", &object_info, 0);
-	}
-
-	return object_type;
-}
+G_DEFINE_TYPE (ShellWindow, shell_window, GTK_TYPE_FRAME);
 
 static void
 shell_window_class_init (ShellWindowClass * klass)
 {
-	parent_class = g_type_class_peek_parent (klass);
-
-	((GtkObjectClass *) klass)->destroy = shell_window_destroy;
 }
 
 static void
@@ -98,11 +69,6 @@ shell_window_new (AppShellData * app_data)
 	return GTK_WIDGET (window);
 }
 
-static void
-shell_window_destroy (GtkObject * obj)
-{
-}
-
 void
 shell_window_clear_resize_handler (ShellWindow * win)
 {



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