Bug 685797 - all python plug-ins are broken after 3b55877a

Remove the privately added GimpItemComboBox class instead, it confuses
the hell out of python. Instead, use g_object_set,get_data() to manage
the newly needed members, and code duplication.
This commit is contained in:
Michael Natterer 2012-10-10 23:10:56 +02:00
parent bc079e6cab
commit d6cf29e8c4

View file

@ -50,71 +50,60 @@
#define WIDTH_REQUEST 200 #define WIDTH_REQUEST 200
#define GIMP_TYPE_ITEM_COMBO_BOX (gimp_item_combo_box_get_type ()) #define GET_PRIVATE(obj) (g_object_get_data (G_OBJECT (obj), "gimp-item-combo-box-private"))
#define GIMP_ITEM_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ITEM_COMBO_BOX, GimpItemComboBox))
#define GIMP_IS_ITEM_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ITEM_COMBO_BOX))
GType gimp_item_combo_box_get_type (void) G_GNUC_CONST;
typedef struct _GimpItemComboBox GimpItemComboBox; typedef struct _GimpItemComboBoxPrivate GimpItemComboBoxPrivate;
struct _GimpItemComboBoxPrivate
{
GimpItemConstraintFunc constraint;
gpointer data;
};
typedef struct _GimpItemComboBoxClass GimpItemComboBoxClass;
typedef struct _GimpDrawableComboBoxClass GimpDrawableComboBoxClass; typedef struct _GimpDrawableComboBoxClass GimpDrawableComboBoxClass;
typedef struct _GimpChannelComboBoxClass GimpChannelComboBoxClass; typedef struct _GimpChannelComboBoxClass GimpChannelComboBoxClass;
typedef struct _GimpLayerComboBoxClass GimpLayerComboBoxClass; typedef struct _GimpLayerComboBoxClass GimpLayerComboBoxClass;
typedef struct _GimpVectorsComboBoxClass GimpVectorsComboBoxClass; typedef struct _GimpVectorsComboBoxClass GimpVectorsComboBoxClass;
struct _GimpItemComboBox
{
GimpIntComboBox parent_instance;
GimpItemConstraintFunc constraint;
gpointer data;
};
struct _GimpItemComboBoxClass
{
GimpIntComboBoxClass parent_class;
};
struct _GimpDrawableComboBox struct _GimpDrawableComboBox
{ {
GimpItemComboBox parent_instance; GimpIntComboBox parent_instance;
}; };
struct _GimpDrawableComboBoxClass struct _GimpDrawableComboBoxClass
{ {
GimpItemComboBoxClass parent_class; GimpIntComboBoxClass parent_class;
}; };
struct _GimpChannelComboBox struct _GimpChannelComboBox
{ {
GimpItemComboBox parent_instance; GimpIntComboBox parent_instance;
}; };
struct _GimpChannelComboBoxClass struct _GimpChannelComboBoxClass
{ {
GimpItemComboBoxClass parent_class; GimpIntComboBoxClass parent_class;
}; };
struct _GimpLayerComboBox struct _GimpLayerComboBox
{ {
GimpItemComboBox parent_instance; GimpIntComboBox parent_instance;
}; };
struct _GimpLayerComboBoxClass struct _GimpLayerComboBoxClass
{ {
GimpItemComboBoxClass parent_class; GimpIntComboBoxClass parent_class;
}; };
struct _GimpVectorsComboBox struct _GimpVectorsComboBox
{ {
GimpItemComboBox parent_instance; GimpIntComboBox parent_instance;
}; };
struct _GimpVectorsComboBoxClass struct _GimpVectorsComboBoxClass
{ {
GimpItemComboBoxClass parent_class; GimpIntComboBoxClass parent_class;
}; };
@ -122,8 +111,8 @@ static GtkWidget * gimp_item_combo_box_new (GType type,
GimpItemConstraintFunc constraint, GimpItemConstraintFunc constraint,
gpointer data); gpointer data);
static void gimp_item_combo_box_populate (GimpItemComboBox *combo_box); static void gimp_item_combo_box_populate (GimpIntComboBox *combo_box);
static void gimp_item_combo_box_model_add (GimpItemComboBox *combo_box, static void gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
GtkListStore *store, GtkListStore *store,
gint32 image, gint32 image,
gint num_items, gint num_items,
@ -138,7 +127,7 @@ static void gimp_item_combo_box_drag_data_received (GtkWidget *widget,
guint info, guint info,
guint time); guint time);
static void gimp_item_combo_box_changed (GimpItemComboBox *combo_box); static void gimp_item_combo_box_changed (GimpIntComboBox *combo_box);
static const GtkTargetEntry targets[] = static const GtkTargetEntry targets[] =
@ -149,29 +138,15 @@ static const GtkTargetEntry targets[] =
}; };
G_DEFINE_TYPE (GimpItemComboBox, gimp_item_combo_box,
GIMP_TYPE_INT_COMBO_BOX)
static void
gimp_item_combo_box_class_init (GimpItemComboBoxClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
}
static void
gimp_item_combo_box_init (GimpItemComboBox *combo_box)
{
}
G_DEFINE_TYPE (GimpDrawableComboBox, gimp_drawable_combo_box, G_DEFINE_TYPE (GimpDrawableComboBox, gimp_drawable_combo_box,
GIMP_TYPE_ITEM_COMBO_BOX) GIMP_TYPE_INT_COMBO_BOX)
static void static void
gimp_drawable_combo_box_class_init (GimpDrawableComboBoxClass *klass) gimp_drawable_combo_box_class_init (GimpDrawableComboBoxClass *klass)
{ {
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
} }
static void static void
@ -183,6 +158,10 @@ gimp_drawable_combo_box_init (GimpDrawableComboBox *combo_box)
GTK_DEST_DEFAULT_DROP, GTK_DEST_DEFAULT_DROP,
targets, 2, targets, 2,
GDK_ACTION_COPY); GDK_ACTION_COPY);
g_object_set_data_full (G_OBJECT (combo_box), "gimp-item-combo-box-private",
g_new0 (GimpItemComboBoxPrivate, 1),
(GDestroyNotify) g_free);
} }
/** /**
@ -214,11 +193,14 @@ gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
G_DEFINE_TYPE (GimpChannelComboBox, gimp_channel_combo_box, G_DEFINE_TYPE (GimpChannelComboBox, gimp_channel_combo_box,
GIMP_TYPE_ITEM_COMBO_BOX) GIMP_TYPE_INT_COMBO_BOX)
static void static void
gimp_channel_combo_box_class_init (GimpChannelComboBoxClass *klass) gimp_channel_combo_box_class_init (GimpChannelComboBoxClass *klass)
{ {
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
} }
static void static void
@ -230,6 +212,10 @@ gimp_channel_combo_box_init (GimpChannelComboBox *combo_box)
GTK_DEST_DEFAULT_DROP, GTK_DEST_DEFAULT_DROP,
targets, 1, targets, 1,
GDK_ACTION_COPY); GDK_ACTION_COPY);
g_object_set_data_full (G_OBJECT (combo_box), "gimp-item-combo-box-private",
g_new0 (GimpItemComboBoxPrivate, 1),
(GDestroyNotify) g_free);
} }
/** /**
@ -254,11 +240,14 @@ gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
G_DEFINE_TYPE (GimpLayerComboBox, gimp_layer_combo_box, G_DEFINE_TYPE (GimpLayerComboBox, gimp_layer_combo_box,
GIMP_TYPE_ITEM_COMBO_BOX) GIMP_TYPE_INT_COMBO_BOX)
static void static void
gimp_layer_combo_box_class_init (GimpLayerComboBoxClass *klass) gimp_layer_combo_box_class_init (GimpLayerComboBoxClass *klass)
{ {
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
} }
static void static void
@ -270,6 +259,10 @@ gimp_layer_combo_box_init (GimpLayerComboBox *combo_box)
GTK_DEST_DEFAULT_DROP, GTK_DEST_DEFAULT_DROP,
targets + 1, 1, targets + 1, 1,
GDK_ACTION_COPY); GDK_ACTION_COPY);
g_object_set_data_full (G_OBJECT (combo_box), "gimp-item-combo-box-private",
g_new0 (GimpItemComboBoxPrivate, 1),
(GDestroyNotify) g_free);
} }
/** /**
@ -294,11 +287,14 @@ gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
G_DEFINE_TYPE (GimpVectorsComboBox, gimp_vectors_combo_box, G_DEFINE_TYPE (GimpVectorsComboBox, gimp_vectors_combo_box,
GIMP_TYPE_ITEM_COMBO_BOX) GIMP_TYPE_INT_COMBO_BOX)
static void static void
gimp_vectors_combo_box_class_init (GimpVectorsComboBoxClass *klass) gimp_vectors_combo_box_class_init (GimpVectorsComboBoxClass *klass)
{ {
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_item_combo_box_drag_data_received;
} }
static void static void
@ -310,6 +306,10 @@ gimp_vectors_combo_box_init (GimpVectorsComboBox *combo_box)
GTK_DEST_DEFAULT_DROP, GTK_DEST_DEFAULT_DROP,
targets + 2, 1, targets + 2, 1,
GDK_ACTION_COPY); GDK_ACTION_COPY);
g_object_set_data_full (G_OBJECT (combo_box), "gimp-item-combo-box-private",
g_new0 (GimpItemComboBoxPrivate, 1),
(GDestroyNotify) g_free);
} }
@ -346,15 +346,18 @@ gimp_item_combo_box_new (GType type,
GimpItemConstraintFunc constraint, GimpItemConstraintFunc constraint,
gpointer data) gpointer data)
{ {
GimpItemComboBox *combo_box; GimpIntComboBox *combo_box;
GimpItemComboBoxPrivate *private;
combo_box = g_object_new (type, combo_box = g_object_new (type,
"width-request", WIDTH_REQUEST, "width-request", WIDTH_REQUEST,
"ellipsize", PANGO_ELLIPSIZE_MIDDLE, "ellipsize", PANGO_ELLIPSIZE_MIDDLE,
NULL); NULL);
combo_box->constraint = constraint; private = GET_PRIVATE (combo_box);
combo_box->data = data;
private->constraint = constraint;
private->data = data;
gimp_item_combo_box_populate (combo_box); gimp_item_combo_box_populate (combo_box);
@ -366,7 +369,7 @@ gimp_item_combo_box_new (GType type,
} }
static void static void
gimp_item_combo_box_populate (GimpItemComboBox *combo_box) gimp_item_combo_box_populate (GimpIntComboBox *combo_box)
{ {
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
@ -420,13 +423,14 @@ gimp_item_combo_box_populate (GimpItemComboBox *combo_box)
} }
static void static void
gimp_item_combo_box_model_add (GimpItemComboBox *combo_box, gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
GtkListStore *store, GtkListStore *store,
gint32 image, gint32 image,
gint num_items, gint num_items,
gint32 *items, gint32 *items,
gint tree_level) gint tree_level)
{ {
GimpItemComboBoxPrivate *private = GET_PRIVATE (combo_box);
GtkTreeIter iter; GtkTreeIter iter;
gint i; gint i;
gchar *indent; gchar *indent;
@ -445,8 +449,8 @@ gimp_item_combo_box_model_add (GimpItemComboBox *combo_box,
for (i = 0; i < num_items; i++) for (i = 0; i < num_items; i++)
{ {
if (! combo_box->constraint || if (! private->constraint ||
(* combo_box->constraint) (image, items[i], combo_box->data)) (* private->constraint) (image, items[i], private->data))
{ {
gchar *image_name = gimp_image_get_name (image); gchar *image_name = gimp_image_get_name (image);
gchar *item_name = gimp_item_get_name (items[i]); gchar *item_name = gimp_item_get_name (items[i]);
@ -534,12 +538,11 @@ gimp_item_combo_box_drag_data_received (GtkWidget *widget,
} }
static void static void
gimp_item_combo_box_changed (GimpItemComboBox *combo_box) gimp_item_combo_box_changed (GimpIntComboBox *combo_box)
{ {
gint item_ID; gint item_ID;
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (combo_box), if (gimp_int_combo_box_get_active (combo_box, &item_ID))
&item_ID))
{ {
if (! gimp_item_is_valid (item_ID)) if (! gimp_item_is_valid (item_ID))
{ {