Commit f26aad19 authored by Matthias Clasen's avatar Matthias Clasen

Boilerplate reduction

parent 33cddd12
2006-05-02 Matthias Clasen <mclasen@redhat.com>
* gtk/*.c: Use G_DEFINE_TYPE and g_type_register_static_simple()
where applicable, for ~5000 lines of code reduction. This also
reduces the size of the data section by ~9k. The overall library
sizes shrinks a bit less, since the text section gets a bit
larger.
2006-05-02 Kristian Rietveld <kris@imendio.com>
* gtk/gtktreeview.c (gtk_tree_view_row_inserted): set tmpnode to
......
2006-05-02 Matthias Clasen <mclasen@redhat.com>
* gtk/*.c: Use G_DEFINE_TYPE and g_type_register_static_simple()
where applicable, for ~5000 lines of code reduction. This also
reduces the size of the data section by ~9k. The overall library
sizes shrinks a bit less, since the text section gets a bit
larger.
2006-05-02 Kristian Rietveld <kris@imendio.com>
* gtk/gtktreeview.c (gtk_tree_view_row_inserted): set tmpnode to
......
......@@ -39,13 +39,10 @@
/* --- prototypes --- */
static void gtk_accel_group_class_init (GtkAccelGroupClass *class);
static void gtk_accel_group_init (GtkAccelGroup *accel_group);
static void gtk_accel_group_finalize (GObject *object);
/* --- variables --- */
static GObjectClass *parent_class = NULL;
static guint signal_accel_activate = 0;
static guint signal_accel_changed = 0;
static guint quark_acceleratable_groups = 0;
......@@ -57,44 +54,14 @@ static guint default_accel_mod_mask = (GDK_SHIFT_MASK |
GDK_META_MASK);
/* --- functions --- */
/**
* gtk_accel_group_get_type:
* @returns: the type ID for accelerator groups.
*/
GType
gtk_accel_group_get_type (void)
{
static GType object_type = 0;
if (!object_type)
{
static const GTypeInfo object_info = {
sizeof (GtkAccelGroupClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gtk_accel_group_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkAccelGroup),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_accel_group_init,
};
object_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkAccelGroup"),
&object_info, 0);
}
return object_type;
}
G_DEFINE_TYPE (GtkAccelGroup, gtk_accel_group, G_TYPE_OBJECT);
/* --- functions --- */
static void
gtk_accel_group_class_init (GtkAccelGroupClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
parent_class = g_type_class_peek_parent (class);
quark_acceleratable_groups = g_quark_from_static_string ("gtk-acceleratable-accel-groups");
object_class->finalize = gtk_accel_group_finalize;
......@@ -171,7 +138,7 @@ gtk_accel_group_finalize (GObject *object)
g_free (accel_group->priv_accels);
G_OBJECT_CLASS (parent_class)->finalize (object);
G_OBJECT_CLASS (gtk_accel_group_parent_class)->finalize (object);
}
static void
......
......@@ -43,8 +43,6 @@ enum {
PROP_ACCEL_WIDGET
};
static void gtk_accel_label_class_init (GtkAccelLabelClass *klass);
static void gtk_accel_label_init (GtkAccelLabel *accel_label);
static void gtk_accel_label_set_property (GObject *object,
guint prop_id,
const GValue *value,
......@@ -62,35 +60,7 @@ static gboolean gtk_accel_label_expose_event (GtkWidget *widget,
static const gchar *gtk_accel_label_get_string (GtkAccelLabel *accel_label);
static GtkLabelClass *parent_class = NULL;
GType
gtk_accel_label_get_type (void)
{
static GType accel_label_type = 0;
if (!accel_label_type)
{
static const GTypeInfo accel_label_info =
{
sizeof (GtkAccelLabelClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_accel_label_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkAccelLabel),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_accel_label_init,
};
accel_label_type =
g_type_register_static (GTK_TYPE_LABEL, I_("GtkAccelLabel"),
&accel_label_info, 0);
}
return accel_label_type;
}
G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL);
static void
gtk_accel_label_class_init (GtkAccelLabelClass *class)
......@@ -99,8 +69,6 @@ gtk_accel_label_class_init (GtkAccelLabelClass *class)
GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
parent_class = g_type_class_peek_parent (class);
gobject_class->finalize = gtk_accel_label_finalize;
gobject_class->set_property = gtk_accel_label_set_property;
gobject_class->get_property = gtk_accel_label_get_property;
......@@ -233,7 +201,7 @@ gtk_accel_label_destroy (GtkObject *object)
gtk_accel_label_set_accel_widget (accel_label, NULL);
gtk_accel_label_set_accel_closure (accel_label, NULL);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
GTK_OBJECT_CLASS (gtk_accel_label_parent_class)->destroy (object);
}
static void
......@@ -243,7 +211,7 @@ gtk_accel_label_finalize (GObject *object)
g_free (accel_label->accel_string);
G_OBJECT_CLASS (parent_class)->finalize (object);
G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
}
/**
......@@ -281,8 +249,8 @@ gtk_accel_label_size_request (GtkWidget *widget,
PangoLayout *layout;
gint width;
if (GTK_WIDGET_CLASS (parent_class)->size_request)
GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request)
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request (widget, requisition);
layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
pango_layout_get_pixel_size (layout, &width, NULL);
......@@ -339,8 +307,8 @@ gtk_accel_label_expose_event (GtkWidget *widget,
pango_layout_get_width (label_layout)
- ac_width * PANGO_SCALE);
if (GTK_WIDGET_CLASS (parent_class)->expose_event)
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
if (direction == GTK_TEXT_DIR_RTL)
widget->allocation.x -= ac_width;
widget->allocation.width += ac_width;
......@@ -374,8 +342,8 @@ gtk_accel_label_expose_event (GtkWidget *widget,
}
else
{
if (GTK_WIDGET_CLASS (parent_class)->expose_event)
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
}
}
......
......@@ -26,7 +26,6 @@
#include "gtkalias.h"
static void gtk_accessible_class_init (GtkAccessibleClass *klass);
static void gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible);
GType
......@@ -35,24 +34,12 @@ gtk_accessible_get_type (void)
static GType accessible_type = 0;
if (!accessible_type)
{
static const GTypeInfo accessible_info =
{
sizeof (GtkAccessibleClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_accessible_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkAccessible),
16, /* n_preallocs */
(GInstanceInitFunc) NULL,
};
accessible_type =
g_type_register_static (ATK_TYPE_OBJECT, I_("GtkAccessible"),
&accessible_info, 0);
}
accessible_type =
g_type_register_static_simple (ATK_TYPE_OBJECT, I_("GtkAccessible"),
sizeof (GtkAccessibleClass),
(GClassInitFunc)gtk_accessible_class_init,
sizeof (GtkAccessible),
NULL, 0);
return accessible_type;
}
......
......@@ -106,41 +106,13 @@ enum
PROP_ACTION_GROUP
};
static void gtk_action_init (GtkAction *action);
static void gtk_action_class_init (GtkActionClass *class);
static GQuark accel_path_id = 0;
static GQuark quark_gtk_action_proxy = 0;
static const gchar accel_path_key[] = "GtkAction::accel_path";
static const gchar gtk_action_proxy_key[] = "gtk-action";
GType
gtk_action_get_type (void)
{
static GtkType type = 0;
if (!type)
{
static const GTypeInfo type_info =
{
sizeof (GtkActionClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gtk_action_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (GtkAction),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_action_init,
};
type = g_type_register_static (G_TYPE_OBJECT,
I_("GtkAction"),
&type_info, 0);
}
return type;
}
G_DEFINE_TYPE (GtkAction, gtk_action, G_TYPE_OBJECT);
static void gtk_action_finalize (GObject *object);
static void gtk_action_set_property (GObject *object,
......@@ -185,7 +157,6 @@ static void closure_accel_activate (GClosure *closure,
gpointer invocation_hint,
gpointer marshal_data);
static GObjectClass *parent_class = NULL;
static guint action_signals[LAST_SIGNAL] = { 0 };
......@@ -197,7 +168,6 @@ gtk_action_class_init (GtkActionClass *klass)
accel_path_id = g_quark_from_static_string (accel_path_key);
quark_gtk_action_proxy = g_quark_from_static_string (gtk_action_proxy_key);
parent_class = g_type_class_peek_parent (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = gtk_action_finalize;
......@@ -449,7 +419,7 @@ gtk_action_finalize (GObject *object)
if (action->private_data->accel_group)
g_object_unref (action->private_data->accel_group);
G_OBJECT_CLASS (parent_class)->finalize (object);
G_OBJECT_CLASS (gtk_action_parent_class)->finalize (object);
}
static void
......
......@@ -49,9 +49,6 @@ enum {
};
static void gtk_adjustment_class_init (GtkAdjustmentClass *klass);
static void gtk_adjustment_init (GtkAdjustment *adjustment);
static void gtk_adjustment_get_property (GObject *object,
guint prop_id,
GValue *value,
......@@ -63,34 +60,7 @@ static void gtk_adjustment_set_property (GObject *object,
static guint adjustment_signals[LAST_SIGNAL] = { 0 };
GType
gtk_adjustment_get_type (void)
{
static GType adjustment_type = 0;
if (!adjustment_type)
{
static const GTypeInfo adjustment_info =
{
sizeof (GtkAdjustmentClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_adjustment_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkAdjustment),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_adjustment_init,
};
adjustment_type =
g_type_register_static (GTK_TYPE_OBJECT, I_("GtkAdjustment"),
&adjustment_info, 0);
}
return adjustment_type;
}
G_DEFINE_TYPE (GtkAdjustment, gtk_adjustment, GTK_TYPE_OBJECT);
static void
gtk_adjustment_class_init (GtkAdjustmentClass *class)
......
......@@ -56,8 +56,6 @@ struct _GtkAlignmentPrivate
guint padding_right;
};
static void gtk_alignment_class_init (GtkAlignmentClass *klass);
static void gtk_alignment_init (GtkAlignment *alignment);
static void gtk_alignment_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_alignment_size_allocate (GtkWidget *widget,
......@@ -71,32 +69,7 @@ static void gtk_alignment_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
GType
gtk_alignment_get_type (void)
{
static GType alignment_type = 0;
if (!alignment_type)
{
static const GTypeInfo alignment_info =
{
sizeof (GtkAlignmentClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_alignment_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkAlignment),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_alignment_init,
};
alignment_type = g_type_register_static (GTK_TYPE_BIN, I_("GtkAlignment"),
&alignment_info, 0);
}
return alignment_type;
}
G_DEFINE_TYPE (GtkAlignment, gtk_alignment, GTK_TYPE_BIN);
static void
gtk_alignment_class_init (GtkAlignmentClass *class)
......
......@@ -43,8 +43,6 @@ enum {
};
static void gtk_arrow_class_init (GtkArrowClass *klass);
static void gtk_arrow_init (GtkArrow *arrow);
static gint gtk_arrow_expose (GtkWidget *widget,
GdkEventExpose *event);
static void gtk_arrow_set_property (GObject *object,
......@@ -56,32 +54,9 @@ static void gtk_arrow_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
GType
gtk_arrow_get_type (void)
{
static GType arrow_type = 0;
if (!arrow_type)
{
static const GTypeInfo arrow_info =
{
sizeof (GtkArrowClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_arrow_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkArrow),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_arrow_init,
};
arrow_type = g_type_register_static (GTK_TYPE_MISC, I_("GtkArrow"),
&arrow_info, 0);
}
G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC);
return arrow_type;
}
static void
gtk_arrow_class_init (GtkArrowClass *class)
......
......@@ -43,8 +43,6 @@ enum {
PROP_OBEY_CHILD
};
static void gtk_aspect_frame_class_init (GtkAspectFrameClass *klass);
static void gtk_aspect_frame_init (GtkAspectFrame *aspect_frame);
static void gtk_aspect_frame_set_property (GObject *object,
guint prop_id,
const GValue *value,
......@@ -59,35 +57,7 @@ static void gtk_aspect_frame_compute_child_allocation (GtkFrame *fram
#define MAX_RATIO 10000.0
#define MIN_RATIO 0.0001
static GtkFrameClass *parent_class = NULL;
GType
gtk_aspect_frame_get_type (void)
{
static GType aspect_frame_type = 0;
if (!aspect_frame_type)
{
static const GTypeInfo aspect_frame_info =
{
sizeof (GtkAspectFrameClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_aspect_frame_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkAspectFrame),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_aspect_frame_init,
};
aspect_frame_type =
g_type_register_static (GTK_TYPE_FRAME, I_("GtkAspectFrame"),
&aspect_frame_info, 0);
}
return aspect_frame_type;
}
G_DEFINE_TYPE (GtkAspectFrame, gtk_aspect_frame, GTK_TYPE_FRAME);
static void
gtk_aspect_frame_class_init (GtkAspectFrameClass *class)
......@@ -95,8 +65,6 @@ gtk_aspect_frame_class_init (GtkAspectFrameClass *class)
GObjectClass *gobject_class;
GtkFrameClass *frame_class;
parent_class = g_type_class_peek_parent (class);
gobject_class = (GObjectClass*) class;
frame_class = (GtkFrameClass*) class;
......@@ -317,7 +285,7 @@ gtk_aspect_frame_compute_child_allocation (GtkFrame *frame,
else
ratio = aspect_frame->ratio;
parent_class->compute_child_allocation (frame, &full_allocation);
GTK_FRAME_CLASS (gtk_aspect_frame_parent_class)->compute_child_allocation (frame, &full_allocation);
if (ratio * full_allocation.height > full_allocation.width)
{
......@@ -334,7 +302,7 @@ gtk_aspect_frame_compute_child_allocation (GtkFrame *frame,
child_allocation->y = full_allocation.y + aspect_frame->yalign * (full_allocation.height - child_allocation->height);
}
else
parent_class->compute_child_allocation (frame, child_allocation);
GTK_FRAME_CLASS (gtk_aspect_frame_parent_class)->compute_child_allocation (frame, child_allocation);
}
#define __GTK_ASPECT_FRAME_C__
......
......@@ -41,8 +41,6 @@ enum {
CHILD_PROP_SECONDARY
};
static void gtk_button_box_class_init (GtkButtonBoxClass *klass);
static void gtk_button_box_init (GtkButtonBox *box);
static void gtk_button_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
......@@ -67,34 +65,7 @@ static void gtk_button_box_get_child_property (GtkContainer *container,
#define DEFAULT_CHILD_IPAD_X 4
#define DEFAULT_CHILD_IPAD_Y 0
GType
gtk_button_box_get_type (void)
{
static GType button_box_type = 0;
if (!button_box_type)
{
static const GTypeInfo button_box_info =
{
sizeof (GtkButtonBoxClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_button_box_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkButtonBox),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_button_box_init,
NULL, /* value_table */
};
button_box_type =
g_type_register_static (GTK_TYPE_BOX, I_("GtkButtonBox"),
&button_box_info, G_TYPE_FLAG_ABSTRACT);
}
return button_box_type;
}
G_DEFINE_ABSTRACT_TYPE (GtkButtonBox, gtk_button_box, GTK_TYPE_BOX);
static void
gtk_button_box_class_init (GtkButtonBoxClass *class)
......
......@@ -29,9 +29,6 @@
#include "gtkintl.h"
#include "gtkalias.h"
static void gtk_bin_class_init (GtkBinClass *klass);
static void gtk_bin_init (GtkBin *bin);
static void gtk_bin_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_bin_remove (GtkContainer *container,
......@@ -43,36 +40,7 @@ static void gtk_bin_forall (GtkContainer *container,
static GType gtk_bin_child_type (GtkContainer *container);
static GtkContainerClass *parent_class = NULL;
GType
gtk_bin_get_type (void)
{
static GType bin_type = 0;
if (!bin_type)
{
static const GTypeInfo bin_info =
{
sizeof (GtkBinClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_bin_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkBin),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_bin_init,
NULL, /* value_table */
};
bin_type = g_type_register_static (GTK_TYPE_CONTAINER, I_("GtkBin"),
&bin_info, G_TYPE_FLAG_ABSTRACT);
}
return bin_type;
}
G_DEFINE_ABSTRACT_TYPE (GtkBin, gtk_bin, GTK_TYPE_CONTAINER);
static void
gtk_bin_class_init (GtkBinClass *class)
......@@ -81,8 +49,6 @@ gtk_bin_class_init (GtkBinClass *class)
container_class = (GtkContainerClass*) class;
parent_class = g_type_class_peek_parent (class);
container_class->add = gtk_bin_add;
container_class->remove = gtk_bin_remove;
container_class->forall = gtk_bin_forall;
......
......@@ -45,8 +45,6 @@ enum {
CHILD_PROP_POSITION
};
static void gtk_box_class_init (GtkBoxClass *klass);
static void gtk_box_init (GtkBox *box);
static void gtk_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
......@@ -76,36 +74,7 @@ static void gtk_box_get_child_property (GtkContainer *container,
static GType gtk_box_child_type (GtkContainer *container);
static GtkContainerClass *parent_class = NULL;
GType
gtk_box_get_type (void)
{
static GType box_type = 0;
if (!box_type)
{
static const GTypeInfo box_info =
{
sizeof (GtkBoxClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_box_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkBox),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_box_init,
NULL, /* value_table */
};
box_type = g_type_register_static (GTK_TYPE_CONTAINER, I_("GtkBox"),
&box_info, G_TYPE_FLAG_ABSTRACT);
}
return box_type;
}
G_DEFINE_ABSTRACT_TYPE (GtkBox, gtk_box, GTK_TYPE_CONTAINER);
static void
gtk_box_class_init (GtkBoxClass *class)
......@@ -113,8 +82,6 @@ gtk_box_class_init (GtkBoxClass *class)
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
parent_class = g_type_class_peek_parent (class);
gobject_class->set_property = gtk_box_set_property;
gobject_class->get_property = gtk_box_get_property;
......
......@@ -84,8 +84,6 @@ struct _GtkButtonPrivate
guint32 grab_time;
};
static void gtk_button_class_init (GtkButtonClass *klass);
static void gtk_button_init (GtkButton *button);
static void gtk_button_destroy (GtkObject *object);
static void gtk_button_set_property (GObject *object,
guint prop_id,
......@@ -139,37 +137,9 @@ static void gtk_button_grab_notify (GtkWidget *widget,
gboolean was_grabbed);
static GtkBinClass *parent_class = NULL;
static guint button_signals[LAST_SIGNAL] = { 0 };
GType
gtk_button_get_type (void)
{
static GType button_type = 0;
if (!button_type)
{
static const GTypeInfo button_info =
{
sizeof (GtkButtonClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_button_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkButton),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_button_init,
};
button_type = g_type_register_static (GTK_TYPE_BIN, I_("GtkButton"),