added enum GimpContainerPolicy.

2003-08-25  Michael Natterer  <mitch@gimp.org>

	* app/core/core-enums.[ch]: added enum GimpContainerPolicy.

	* app/core/gimpcontainer.[ch]: removed it here.  Added new virtual
	function GimpContainer::clear() which removes all items. Cleanup.

	* app/core/gimplist.c: implement GimpContainer::clear(). Cleanup.
This commit is contained in:
Michael Natterer 2003-08-25 21:25:13 +00:00 committed by Michael Natterer
parent 9209b3f728
commit dc95e16b79
6 changed files with 90 additions and 67 deletions

View file

@ -1,3 +1,12 @@
2003-08-25 Michael Natterer <mitch@gimp.org>
* app/core/core-enums.[ch]: added enum GimpContainerPolicy.
* app/core/gimpcontainer.[ch]: removed it here. Added new virtual
function GimpContainer::clear() which removes all items. Cleanup.
* app/core/gimplist.c: implement GimpContainer::clear(). Cleanup.
2003-08-25 Michael Natterer <mitch@gimp.org> 2003-08-25 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpitemfactory.[ch] * app/widgets/gimpitemfactory.[ch]

View file

@ -115,6 +115,25 @@ gimp_channel_type_get_type (void)
} }
static const GEnumValue gimp_container_policy_enum_values[] =
{
{ GIMP_CONTAINER_POLICY_STRONG, "GIMP_CONTAINER_POLICY_STRONG", "strong" },
{ GIMP_CONTAINER_POLICY_WEAK, "GIMP_CONTAINER_POLICY_WEAK", "weak" },
{ 0, NULL, NULL }
};
GType
gimp_container_policy_get_type (void)
{
static GType enum_type = 0;
if (!enum_type)
enum_type = g_enum_register_static ("GimpContainerPolicy", gimp_container_policy_enum_values);
return enum_type;
}
static const GEnumValue gimp_convert_dither_type_enum_values[] = static const GEnumValue gimp_convert_dither_type_enum_values[] =
{ {
{ GIMP_NO_DITHER, N_("No Color Dithering"), "no-dither" }, { GIMP_NO_DITHER, N_("No Color Dithering"), "no-dither" },

View file

@ -21,18 +21,18 @@
#if 0 #if 0
This file is parsed by two scripts, enumgen.pl in tools/pdbgen, This file is parsed by two scripts, enumgen.pl in tools/pdbgen,
and gimp-mkenums. All enums that are not marked with and gimp-mkenums. All enums that are not marked with
/*< pdb-skip >*/ are exported to libgimp and the PDB. Enums that are /*< pdb-skip >*/ are exported to libgimp and the PDB. Enums that are
not marked with /*< skip >*/ are registered with the GType system. not marked with /*< skip >*/ are registered with the GType system.
If you want the enum to be skipped by both scripts, you have to use If you want the enum to be skipped by both scripts, you have to use
/*< pdb-skip, skip >*/. /*< pdb-skip, skip >*/.
All enum values that are marked with /*< skip >*/ are skipped for All enum values that are marked with /*< skip >*/ are skipped for
both targets. both targets.
#endif #endif
/* /*
* these enums that are registered with the type system * these enums that are registered with the type system
*/ */
@ -103,6 +103,17 @@ typedef enum
} GimpChannelType; } GimpChannelType;
#define GIMP_TYPE_CONTAINER_POLICY (gimp_container_policy_get_type ())
GType gimp_container_policy_get_type (void) G_GNUC_CONST;
typedef enum /*< pdb-skip >*/
{
GIMP_CONTAINER_POLICY_STRONG,
GIMP_CONTAINER_POLICY_WEAK
} GimpContainerPolicy;
#define GIMP_TYPE_CONVERT_DITHER_TYPE (gimp_convert_dither_type_get_type ()) #define GIMP_TYPE_CONVERT_DITHER_TYPE (gimp_convert_dither_type_get_type ())
GType gimp_convert_dither_type_get_type (void) G_GNUC_CONST; GType gimp_convert_dither_type_get_type (void) G_GNUC_CONST;
@ -142,7 +153,7 @@ GType gimp_fill_type_get_type (void) G_GNUC_CONST;
typedef enum typedef enum
{ {
GIMP_FOREGROUND_FILL, /*< desc="Foreground" >*/ GIMP_FOREGROUND_FILL, /*< desc="Foreground" >*/
GIMP_BACKGROUND_FILL, /*< desc="Background" >*/ GIMP_BACKGROUND_FILL, /*< desc="Background" >*/
GIMP_WHITE_FILL, /*< desc="White" >*/ GIMP_WHITE_FILL, /*< desc="White" >*/
GIMP_TRANSPARENT_FILL, /*< desc="Transparent" >*/ GIMP_TRANSPARENT_FILL, /*< desc="Transparent" >*/
@ -156,7 +167,7 @@ GType gimp_gradient_type_get_type (void) G_GNUC_CONST;
typedef enum typedef enum
{ {
GIMP_LINEAR, /*< desc="Linear" >*/ GIMP_LINEAR, /*< desc="Linear" >*/
GIMP_BILINEAR, /*< desc="Bi-Linear" >*/ GIMP_BILINEAR, /*< desc="Bi-Linear" >*/
GIMP_RADIAL, /*< desc="Radial" >*/ GIMP_RADIAL, /*< desc="Radial" >*/
GIMP_SQUARE, /*< desc="Square" >*/ GIMP_SQUARE, /*< desc="Square" >*/

View file

@ -113,32 +113,11 @@ static void gimp_container_disconnect_callback (GimpObject *object,
gpointer data); gpointer data);
static guint container_signals[LAST_SIGNAL] = { 0 }; static guint container_signals[LAST_SIGNAL] = { 0, };
static GimpObjectClass *parent_class = NULL; 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 GType
gimp_container_get_type (void) gimp_container_get_type (void)
{ {
@ -158,7 +137,7 @@ gimp_container_get_type (void)
0, /* n_preallocs */ 0, /* n_preallocs */
(GInstanceInitFunc) gimp_container_init, (GInstanceInitFunc) gimp_container_init,
}; };
static const GInterfaceInfo config_iface_info = static const GInterfaceInfo config_iface_info =
{ {
(GInterfaceInitFunc) gimp_container_config_iface_init, (GInterfaceInitFunc) gimp_container_config_iface_init,
NULL, /* iface_finalize */ NULL, /* iface_finalize */
@ -166,7 +145,7 @@ gimp_container_get_type (void)
}; };
container_type = g_type_register_static (GIMP_TYPE_OBJECT, container_type = g_type_register_static (GIMP_TYPE_OBJECT,
"GimpContainer", "GimpContainer",
&container_info, 0); &container_info, 0);
g_type_add_interface_static (container_type, g_type_add_interface_static (container_type,
@ -249,6 +228,7 @@ gimp_container_class_init (GimpContainerClass *klass)
klass->freeze = NULL; klass->freeze = NULL;
klass->thaw = NULL; klass->thaw = NULL;
klass->clear = NULL;
klass->have = NULL; klass->have = NULL;
klass->foreach = NULL; klass->foreach = NULL;
klass->get_child_by_name = NULL; klass->get_child_by_name = NULL;
@ -296,11 +276,9 @@ gimp_container_dispose (GObject *object)
container = GIMP_CONTAINER (object); container = GIMP_CONTAINER (object);
while (container->handlers) while (container->handlers)
{ gimp_container_remove_handler (container,
gimp_container_remove_handler (container, ((GimpContainerHandler *)
((GimpContainerHandler *) container->handlers->data)->quark);
container->handlers->data)->quark);
}
if (container->children_type != G_TYPE_NONE) if (container->children_type != G_TYPE_NONE)
{ {
@ -372,13 +350,11 @@ gimp_container_get_memsize (GimpObject *object,
for (list = container->handlers; list; list = g_list_next (list)) for (list = container->handlers; list; list = g_list_next (list))
{ {
GimpContainerHandler *handler; GimpContainerHandler *handler = list->data;
handler = (GimpContainerHandler *) list->data;
memsize += (sizeof (GList) + memsize += (sizeof (GList) +
sizeof (GimpContainerHandler) + sizeof (GimpContainerHandler) +
strlen (handler->signame)); strlen (handler->signame) + 1);
} }
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
@ -677,8 +653,8 @@ gimp_container_remove (GimpContainer *container,
{ {
handler = (GimpContainerHandler *) list->data; handler = (GimpContainerHandler *) list->data;
handler_id = GPOINTER_TO_UINT handler_id = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (object),
(g_object_get_qdata (G_OBJECT (object), handler->quark)); handler->quark));
if (handler_id) if (handler_id)
{ {
@ -799,6 +775,19 @@ gimp_container_frozen (GimpContainer *container)
return (container->freeze_count > 0) ? TRUE : FALSE; return (container->freeze_count > 0) ? TRUE : FALSE;
} }
void
gimp_container_clear (GimpContainer *container)
{
g_return_if_fail (GIMP_IS_CONTAINER (container));
if (container->num_children > 0)
{
gimp_container_freeze (container);
GIMP_CONTAINER_GET_CLASS (container)->clear (container);
gimp_container_thaw (container);
}
}
gboolean gboolean
gimp_container_have (GimpContainer *container, gimp_container_have (GimpContainer *container,
GimpObject *object) GimpObject *object)
@ -819,10 +808,8 @@ gimp_container_foreach (GimpContainer *container,
g_return_if_fail (GIMP_IS_CONTAINER (container)); g_return_if_fail (GIMP_IS_CONTAINER (container));
g_return_if_fail (func != NULL); g_return_if_fail (func != NULL);
if (container->num_children < 1) if (container->num_children > 0)
return; GIMP_CONTAINER_GET_CLASS (container)->foreach (container, func, user_data);
GIMP_CONTAINER_GET_CLASS (container)->foreach (container, func, user_data);
} }
GimpObject * GimpObject *
@ -925,9 +912,8 @@ gimp_container_remove_handler_foreach_func (GimpObject *object,
{ {
gulong handler_id; gulong handler_id;
handler_id = handler_id = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (object),
GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (object), handler->quark));
handler->quark));
if (handler_id) if (handler_id)
{ {

View file

@ -26,14 +26,6 @@
#include "gimpobject.h" #include "gimpobject.h"
typedef enum
{
GIMP_CONTAINER_POLICY_STRONG,
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_TYPE_CONTAINER (gimp_container_get_type ())
#define GIMP_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTAINER, GimpContainer)) #define GIMP_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTAINER, GimpContainer))
#define GIMP_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTAINER, GimpContainerClass)) #define GIMP_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTAINER, GimpContainerClass))
@ -74,6 +66,7 @@ struct _GimpContainerClass
void (* thaw) (GimpContainer *container); void (* thaw) (GimpContainer *container);
/* virtual functions */ /* virtual functions */
void (* clear) (GimpContainer *container);
gboolean (* have) (const GimpContainer *container, gboolean (* have) (const GimpContainer *container,
const GimpObject *object); const GimpObject *object);
void (* foreach) (const GimpContainer *container, void (* foreach) (const GimpContainer *container,
@ -88,8 +81,6 @@ struct _GimpContainerClass
}; };
GType gimp_container_policy_get_type (void) G_GNUC_CONST;
GType gimp_container_get_type (void) G_GNUC_CONST; GType gimp_container_get_type (void) G_GNUC_CONST;
GType gimp_container_children_type (const GimpContainer *container); GType gimp_container_children_type (const GimpContainer *container);
@ -111,6 +102,7 @@ void gimp_container_freeze (GimpContainer *container);
void gimp_container_thaw (GimpContainer *container); void gimp_container_thaw (GimpContainer *container);
gboolean gimp_container_frozen (GimpContainer *container); gboolean gimp_container_frozen (GimpContainer *container);
void gimp_container_clear (GimpContainer *container);
gboolean gimp_container_have (GimpContainer *container, gboolean gimp_container_have (GimpContainer *container,
GimpObject *object); GimpObject *object);
void gimp_container_foreach (GimpContainer *container, void gimp_container_foreach (GimpContainer *container,

View file

@ -46,6 +46,7 @@ static void gimp_list_remove (GimpContainer *container
static void gimp_list_reorder (GimpContainer *container, static void gimp_list_reorder (GimpContainer *container,
GimpObject *object, GimpObject *object,
gint new_index); gint new_index);
static void gimp_list_clear (GimpContainer *container);
static gboolean gimp_list_have (const GimpContainer *container, static gboolean gimp_list_have (const GimpContainer *container,
const GimpObject *object); const GimpObject *object);
static void gimp_list_foreach (const GimpContainer *container, static void gimp_list_foreach (const GimpContainer *container,
@ -110,6 +111,7 @@ gimp_list_class_init (GimpListClass *klass)
container_class->add = gimp_list_add; container_class->add = gimp_list_add;
container_class->remove = gimp_list_remove; container_class->remove = gimp_list_remove;
container_class->reorder = gimp_list_reorder; container_class->reorder = gimp_list_reorder;
container_class->clear = gimp_list_clear;
container_class->have = gimp_list_have; container_class->have = gimp_list_have;
container_class->foreach = gimp_list_foreach; container_class->foreach = gimp_list_foreach;
container_class->get_child_by_name = gimp_list_get_child_by_name; container_class->get_child_by_name = gimp_list_get_child_by_name;
@ -131,10 +133,7 @@ gimp_list_dispose (GObject *object)
list = GIMP_LIST (object); list = GIMP_LIST (object);
while (list->list) while (list->list)
{ gimp_container_remove (GIMP_CONTAINER (list), list->list->data);
gimp_container_remove (GIMP_CONTAINER (list),
GIMP_OBJECT (list->list->data));
}
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
} }
@ -203,6 +202,17 @@ gimp_list_reorder (GimpContainer *container,
list->list = g_list_insert (list->list, object, new_index); list->list = g_list_insert (list->list, object, new_index);
} }
static void
gimp_list_clear (GimpContainer *container)
{
GimpList *list;
list = GIMP_LIST (container);
while (list->list)
gimp_container_remove (container, list->list->data);
}
static gboolean static gboolean
gimp_list_have (const GimpContainer *container, gimp_list_have (const GimpContainer *container,
const GimpObject *object) const GimpObject *object)
@ -301,9 +311,7 @@ gimp_list_reverse (GimpList *list)
if (GIMP_CONTAINER (list)->num_children > 1) if (GIMP_CONTAINER (list)->num_children > 1)
{ {
gimp_container_freeze (GIMP_CONTAINER (list)); gimp_container_freeze (GIMP_CONTAINER (list));
list->list = g_list_reverse (list->list); list->list = g_list_reverse (list->list);
gimp_container_thaw (GIMP_CONTAINER (list)); gimp_container_thaw (GIMP_CONTAINER (list));
} }
} }
@ -318,9 +326,7 @@ gimp_list_sort (GimpList *list,
if (GIMP_CONTAINER (list)->num_children > 1) if (GIMP_CONTAINER (list)->num_children > 1)
{ {
gimp_container_freeze (GIMP_CONTAINER (list)); gimp_container_freeze (GIMP_CONTAINER (list));
list->list = g_list_sort (list->list, compare_func); list->list = g_list_sort (list->list, compare_func);
gimp_container_thaw (GIMP_CONTAINER (list)); gimp_container_thaw (GIMP_CONTAINER (list));
} }
} }