Commit 31f690cf authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added properties for "children_type" and "policy". Ref/unref the

2001-10-18  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpcontainer.[ch]: added properties for "children_type"
	and "policy". Ref/unref the "children_type" class so we can do
	signal lookups and use other introspection features without an
	existing instance of "children_type".

	The new properties are G_PARAM_CONSTRUCT_ONLY and *MUST* be passed
	to g_object_new() to ref/unref children_type's class correctly.

	* app/core/gimpdatalist.c
	* app/core/gimplist.c: pass them as construct properties.

	* app/core/gimp.c: no need to manually ref classes any more.
parent 262c17bb
2001-10-18 Michael Natterer <mitch@gimp.org>
* app/core/gimpcontainer.[ch]: added properties for "children_type"
and "policy". Ref/unref the "children_type" class so we can do
signal lookups and use other introspection features without an
existing instance of "children_type".
The new properties are G_PARAM_CONSTRUCT_ONLY and *MUST* be passed
to g_object_new() to ref/unref children_type's class correctly.
* app/core/gimpdatalist.c
* app/core/gimplist.c: pass them as construct properties.
* app/core/gimp.c: no need to manually ref classes any more.
2001-10-17 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpchannellistview.c: added a handler for GimpImage's
......
......@@ -291,12 +291,6 @@ gimp_new (void)
{
Gimp *gimp;
/* EEK */
g_type_class_ref (GIMP_TYPE_CONTEXT);
g_type_class_ref (GIMP_TYPE_CONTAINER);
g_type_class_ref (GIMP_TYPE_IMAGE);
g_type_class_ref (GIMP_TYPE_IMAGEFILE);
gimp = g_object_new (GIMP_TYPE_GIMP, NULL);
return gimp;
......@@ -314,31 +308,23 @@ gimp_initialize (Gimp *gimp)
{ gimp_brush_generated_load, GIMP_BRUSH_GENERATED_FILE_EXTENSION },
{ gimp_brush_pipe_load, GIMP_BRUSH_PIPE_FILE_EXTENSION }
};
static gint n_brush_loader_entries = (sizeof (brush_loader_entries) /
sizeof (brush_loader_entries[0]));
static const GimpDataFactoryLoaderEntry pattern_loader_entries[] =
{
{ gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION }
};
static gint n_pattern_loader_entries = (sizeof (pattern_loader_entries) /
sizeof (pattern_loader_entries[0]));
static const GimpDataFactoryLoaderEntry gradient_loader_entries[] =
{
{ gimp_gradient_load, GIMP_GRADIENT_FILE_EXTENSION },
{ gimp_gradient_load, NULL /* legacy loader */ }
};
static gint n_gradient_loader_entries = (sizeof (gradient_loader_entries) /
sizeof (gradient_loader_entries[0]));
static const GimpDataFactoryLoaderEntry palette_loader_entries[] =
{
{ gimp_palette_load, GIMP_PALETTE_FILE_EXTENSION },
{ gimp_palette_load, NULL /* legacy loader */ }
};
static gint n_palette_loader_entries = (sizeof (palette_loader_entries) /
sizeof (palette_loader_entries[0]));
g_return_if_fail (GIMP_IS_GIMP (gimp));
......@@ -346,7 +332,7 @@ gimp_initialize (Gimp *gimp)
gimp_data_factory_new (GIMP_TYPE_BRUSH,
(const gchar **) &gimp->config->brush_path,
brush_loader_entries,
n_brush_loader_entries,
G_N_ELEMENTS (brush_loader_entries),
gimp_brush_new,
gimp_brush_get_standard);
......@@ -354,7 +340,7 @@ gimp_initialize (Gimp *gimp)
gimp_data_factory_new (GIMP_TYPE_PATTERN,
(const gchar **) &gimp->config->pattern_path,
pattern_loader_entries,
n_pattern_loader_entries,
G_N_ELEMENTS (pattern_loader_entries),
gimp_pattern_new,
gimp_pattern_get_standard);
......@@ -362,7 +348,7 @@ gimp_initialize (Gimp *gimp)
gimp_data_factory_new (GIMP_TYPE_GRADIENT,
(const gchar **) &gimp->config->gradient_path,
gradient_loader_entries,
n_gradient_loader_entries,
G_N_ELEMENTS (gradient_loader_entries),
gimp_gradient_new,
gimp_gradient_get_standard);
......@@ -370,7 +356,7 @@ gimp_initialize (Gimp *gimp)
gimp_data_factory_new (GIMP_TYPE_PALETTE,
(const gchar **) &gimp->config->palette_path,
palette_loader_entries,
n_palette_loader_entries,
G_N_ELEMENTS (palette_loader_entries),
gimp_palette_new,
gimp_palette_get_standard);
......
......@@ -49,6 +49,13 @@ enum
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_CHILDREN_TYPE,
PROP_POLICY
};
/* local function prototypes */
......@@ -57,6 +64,15 @@ static void gimp_container_init (GimpContainer *container)
static void gimp_container_dispose (GObject *object);
static void gimp_container_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_container_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_container_disconnect_callback (GimpObject *object,
gpointer data);
......@@ -66,6 +82,27 @@ static guint container_signals[LAST_SIGNAL] = { 0 };
static GimpObjectClass *parent_class = NULL;
GType
gimp_container_policy_get_type (void)
{
static GType policy_type = 0;
if (! policy_type)
{
static const GEnumValue container_policy_values[] =
{
{ GIMP_CONTAINER_POLICY_STRONG, "GIMP_CONTAINER_POLICY_STRONG", "strong" },
{ GIMP_CONTAINER_POLICY_WEAK, "GIMP_CONTAINER_POLICY_WEAK", "weak" },
{ 0, NULL, NULL }
};
policy_type = g_enum_register_static ("GimpContainerPolicy",
container_policy_values);
}
return policy_type;
}
GType
gimp_container_get_type (void)
{
......@@ -152,25 +189,52 @@ gimp_container_class_init (GimpContainerClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->dispose = gimp_container_dispose;
klass->add = NULL;
klass->remove = NULL;
klass->reorder = NULL;
klass->freeze = NULL;
klass->thaw = NULL;
klass->have = NULL;
klass->foreach = NULL;
klass->get_child_by_name = NULL;
klass->get_child_by_index = NULL;
klass->get_child_index = NULL;
object_class->dispose = gimp_container_dispose;
object_class->set_property = gimp_container_set_property;
object_class->get_property = gimp_container_get_property;
klass->add = NULL;
klass->remove = NULL;
klass->reorder = NULL;
klass->freeze = NULL;
klass->thaw = NULL;
klass->have = NULL;
klass->foreach = NULL;
klass->get_child_by_name = NULL;
klass->get_child_by_index = NULL;
klass->get_child_index = NULL;
/* spit out a warning once GType becomes a gpointer */
{
guint32 *foo = NULL;
GType *bar;
bar = foo;
}
g_object_class_install_property (object_class,
PROP_CHILDREN_TYPE,
g_param_spec_uint ("children_type",
NULL, NULL,
GIMP_TYPE_OBJECT,
G_MAXINT,
GIMP_TYPE_OBJECT,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_POLICY,
g_param_spec_enum ("policy",
NULL, NULL,
GIMP_TYPE_CONTAINER_POLICY,
GIMP_CONTAINER_POLICY_STRONG,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_container_init (GimpContainer *container)
{
container->children_type = GIMP_TYPE_OBJECT;
container->children_type = G_TYPE_NONE;
container->policy = GIMP_CONTAINER_POLICY_STRONG;
container->num_children = 0;
......@@ -192,9 +256,64 @@ gimp_container_dispose (GObject *object)
container->handlers->data)->quark);
}
if (container->children_type != G_TYPE_NONE)
{
g_type_class_unref (g_type_class_peek (container->children_type));
container->children_type = G_TYPE_NONE;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_container_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpContainer *container;
container = GIMP_CONTAINER (object);
switch (property_id)
{
case PROP_CHILDREN_TYPE:
container->children_type = (GType) g_value_get_uint (value);
g_type_class_ref (container->children_type);
break;
case PROP_POLICY:
container->policy = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_container_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpContainer *container;
container = GIMP_CONTAINER (object);
switch (property_id)
{
case PROP_CHILDREN_TYPE:
g_value_set_uint (value, (guint) container->children_type);
break;
case PROP_POLICY:
g_value_set_enum (value, container->policy);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_container_disconnect_callback (GimpObject *object,
gpointer data)
......
......@@ -32,6 +32,7 @@ typedef enum
GIMP_CONTAINER_POLICY_WEAK
} GimpContainerPolicy;
#define GIMP_TYPE_CONTAINER_POLICY (gimp_container_policy_get_type ())
#define GIMP_TYPE_CONTAINER (gimp_container_get_type ())
#define GIMP_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTAINER, GimpContainer))
......@@ -87,6 +88,8 @@ struct _GimpContainerClass
};
GType gimp_container_policy_get_type (void);
GType gimp_container_get_type (void);
GType gimp_container_children_type (const GimpContainer *container);
......
......@@ -141,10 +141,10 @@ gimp_data_list_new (GType children_type)
g_return_val_if_fail (g_type_is_a (children_type, GIMP_TYPE_DATA), NULL);
list = GIMP_DATA_LIST (g_object_new (GIMP_TYPE_DATA_LIST, NULL));
GIMP_CONTAINER (list)->children_type = children_type;
GIMP_CONTAINER (list)->policy = GIMP_CONTAINER_POLICY_STRONG;
list = g_object_new (GIMP_TYPE_DATA_LIST,
"children_type", children_type,
"policy", GIMP_CONTAINER_POLICY_STRONG,
NULL);
return GIMP_CONTAINER (list);
}
......
......@@ -203,10 +203,10 @@ gimp_list_new (GType children_type,
g_return_val_if_fail (policy == GIMP_CONTAINER_POLICY_STRONG ||
policy == GIMP_CONTAINER_POLICY_WEAK, NULL);
list = g_object_new (GIMP_TYPE_LIST, NULL);
GIMP_CONTAINER (list)->children_type = children_type;
GIMP_CONTAINER (list)->policy = policy;
list = g_object_new (GIMP_TYPE_LIST,
"children_type", children_type,
"policy", policy,
NULL);
return GIMP_CONTAINER (list);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment