Commit 6642bc2c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

removed the "name" parameter and use GimpObject's name instead.

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

	* app/gimpdrawable.[ch]: removed the "name" parameter and use
	GimpObject's name instead.

	* app/channel.c
	* app/channel_ops.c
	* app/channels_dialog.c
	* app/drawable.h
	* app/gimpimage.c
	* app/interface.c
	* app/layer.c
	* app/layer_select.c
	* app/layers_dialog.c
	* app/qmask.c
	* app/undo.c
	* app/xcf.c: changed accordingly, cleanup.
parent 65543971
2001-01-10 Michael Natterer <mitch@gimp.org>
* app/gimpdrawable.[ch]: removed the "name" parameter and use
GimpObject's name instead.
* app/channel.c
* app/channel_ops.c
* app/channels_dialog.c
* app/drawable.h
* app/gimpimage.c
* app/interface.c
* app/layer.c
* app/layer_select.c
* app/layers_dialog.c
* app/qmask.c
* app/undo.c
* app/xcf.c: changed accordingly, cleanup.
2001-01-10 Michael Natterer <mitch@gimp.org>
* app/gimpbrushlist.c
......
......@@ -229,7 +229,7 @@ qmask_activate (GtkWidget *widget,
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, color);
drawable_set_name (GIMP_DRAWABLE (gmask), "Qmask");
gimp_object_set_name (GIMP_OBJECT (gmask), "Qmask");
channel_set_opacity (gmask, opacity);
gimage_mask_none (gimg); /* Clear the selection */
}
......
......@@ -229,7 +229,7 @@ qmask_activate (GtkWidget *widget,
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, color);
drawable_set_name (GIMP_DRAWABLE (gmask), "Qmask");
gimp_object_set_name (GIMP_OBJECT (gmask), "Qmask");
channel_set_opacity (gmask, opacity);
gimage_mask_none (gimg); /* Clear the selection */
}
......
......@@ -187,7 +187,8 @@ channel_copy (const Channel *channel)
gint len;
/* formulate the new channel name */
name = drawable_get_name (GIMP_DRAWABLE (channel));
name = gimp_object_get_name (GIMP_OBJECT (channel));
ext = strrchr (name, '#');
len = strlen (_("copy"));
if ((strlen (name) >= len &&
......@@ -231,13 +232,13 @@ void
channel_set_name (Channel *channel,
const gchar *name)
{
gimp_drawable_set_name (GIMP_DRAWABLE (channel), name);
gimp_object_set_name (GIMP_OBJECT (channel), name);
}
const gchar *
channel_get_name (const Channel *channel)
{
return gimp_drawable_get_name (GIMP_DRAWABLE (channel));
return gimp_object_get_name (GIMP_OBJECT (channel));
}
void
......
......@@ -612,8 +612,8 @@ duplicate (GimpImage *gimage)
/* Make sure if the layer has a layer mask, it's name isn't screwed up */
if (new_layer->mask)
{
gimp_drawable_set_name(GIMP_DRAWABLE(new_layer->mask),
gimp_drawable_get_name(GIMP_DRAWABLE(layer->mask)));
gimp_object_set_name (GIMP_OBJECT (new_layer->mask),
gimp_object_get_name (GIMP_OBJECT (layer->mask)));
}
if (gimage->active_layer == layer)
......@@ -643,8 +643,8 @@ duplicate (GimpImage *gimage)
gimp_drawable_set_gimage(GIMP_DRAWABLE(new_channel), new_gimage);
/* Make sure the copied channel doesn't say: "<old channel> copy" */
gimp_drawable_set_name(GIMP_DRAWABLE(new_channel),
gimp_drawable_get_name(GIMP_DRAWABLE(channel)));
gimp_object_set_name (GIMP_OBJECT (new_channel),
gimp_object_get_name (GIMP_OBJECT (channel)));
if (gimage->active_channel == channel)
active_channel = (new_channel);
......
......@@ -1462,7 +1462,7 @@ channel_widget_create (GimpImage *gimage,
case AUXILLARY_CHANNEL:
channel_widget->label =
gtk_label_new (drawable_get_name (GIMP_DRAWABLE (channel)));
gtk_label_new (gimp_object_get_name (GIMP_OBJECT (channel)));
break;
}
......@@ -2650,10 +2650,10 @@ edit_channel_query_ok_callback (GtkWidget *widget,
if (options->gimage)
{
/* Set the new channel name */
drawable_set_name (GIMP_DRAWABLE (channel),
gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
gimp_object_set_name (GIMP_OBJECT (channel),
gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
gtk_label_set_text (GTK_LABEL (options->channel_widget->label),
drawable_get_name (GIMP_DRAWABLE (channel)));
gimp_object_get_name (GIMP_OBJECT (channel)));
if (channel->opacity != opacity)
{
......@@ -2755,7 +2755,7 @@ channels_dialog_edit_channel_query (ChannelWidget *channel_widget)
1, 2, 0, 1);
gtk_entry_set_text
(GTK_ENTRY (options->name_entry),
drawable_get_name (GIMP_DRAWABLE (channel_widget->channel)));
gimp_object_get_name (GIMP_OBJECT (channel_widget->channel)));
gtk_widget_show (options->name_entry);
/* The opacity scale */
......
......@@ -187,7 +187,8 @@ channel_copy (const Channel *channel)
gint len;
/* formulate the new channel name */
name = drawable_get_name (GIMP_DRAWABLE (channel));
name = gimp_object_get_name (GIMP_OBJECT (channel));
ext = strrchr (name, '#');
len = strlen (_("copy"));
if ((strlen (name) >= len &&
......@@ -231,13 +232,13 @@ void
channel_set_name (Channel *channel,
const gchar *name)
{
gimp_drawable_set_name (GIMP_DRAWABLE (channel), name);
gimp_object_set_name (GIMP_OBJECT (channel), name);
}
const gchar *
channel_get_name (const Channel *channel)
{
return gimp_drawable_get_name (GIMP_DRAWABLE (channel));
return gimp_object_get_name (GIMP_OBJECT (channel));
}
void
......
......@@ -187,7 +187,8 @@ channel_copy (const Channel *channel)
gint len;
/* formulate the new channel name */
name = drawable_get_name (GIMP_DRAWABLE (channel));
name = gimp_object_get_name (GIMP_OBJECT (channel));
ext = strrchr (name, '#');
len = strlen (_("copy"));
if ((strlen (name) >= len &&
......@@ -231,13 +232,13 @@ void
channel_set_name (Channel *channel,
const gchar *name)
{
gimp_drawable_set_name (GIMP_DRAWABLE (channel), name);
gimp_object_set_name (GIMP_OBJECT (channel), name);
}
const gchar *
channel_get_name (const Channel *channel)
{
return gimp_drawable_get_name (GIMP_DRAWABLE (channel));
return gimp_object_get_name (GIMP_OBJECT (channel));
}
void
......
......@@ -612,8 +612,8 @@ duplicate (GimpImage *gimage)
/* Make sure if the layer has a layer mask, it's name isn't screwed up */
if (new_layer->mask)
{
gimp_drawable_set_name(GIMP_DRAWABLE(new_layer->mask),
gimp_drawable_get_name(GIMP_DRAWABLE(layer->mask)));
gimp_object_set_name (GIMP_OBJECT (new_layer->mask),
gimp_object_get_name (GIMP_OBJECT (layer->mask)));
}
if (gimage->active_layer == layer)
......@@ -643,8 +643,8 @@ duplicate (GimpImage *gimage)
gimp_drawable_set_gimage(GIMP_DRAWABLE(new_channel), new_gimage);
/* Make sure the copied channel doesn't say: "<old channel> copy" */
gimp_drawable_set_name(GIMP_DRAWABLE(new_channel),
gimp_drawable_get_name(GIMP_DRAWABLE(channel)));
gimp_object_set_name (GIMP_OBJECT (new_channel),
gimp_object_get_name (GIMP_OBJECT (channel)));
if (gimage->active_channel == channel)
active_channel = (new_channel);
......
......@@ -52,9 +52,10 @@ enum
LAST_SIGNAL
};
static void gimp_drawable_class_init (GimpDrawableClass *klass);
static void gimp_drawable_init (GimpDrawable *drawable);
static void gimp_drawable_destroy (GtkObject *object);
static void gimp_drawable_class_init (GimpDrawableClass *klass);
static void gimp_drawable_init (GimpDrawable *drawable);
static void gimp_drawable_destroy (GtkObject *object);
static void gimp_drawable_name_changed (GimpObject *drawable);
static guint gimp_drawable_signals[LAST_SIGNAL] = { 0 };
......@@ -90,9 +91,11 @@ gimp_drawable_get_type (void)
static void
gimp_drawable_class_init (GimpDrawableClass *klass)
{
GtkObjectClass *object_class;
GtkObjectClass *object_class;
GimpObjectClass *gimp_object_class;
object_class = (GtkObjectClass *) klass;
object_class = (GtkObjectClass *) klass;
gimp_object_class = (GimpObjectClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_OBJECT);
......@@ -110,9 +113,105 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
object_class->destroy = gimp_drawable_destroy;
gimp_object_class->name_changed = gimp_drawable_name_changed;
klass->invalidate_preview = NULL;
}
static void
gimp_drawable_name_changed (GimpObject *object)
{
GimpDrawable *drawable;
GimpDrawable *drawable2;
GSList *list, *list2, *base_list;
gint unique_ext = 0;
gchar *ext;
gchar *new_name = NULL;
g_return_if_fail (GIMP_IS_DRAWABLE (object));
drawable = GIMP_DRAWABLE (object);
/* if no other layers to check name against */
if (drawable->gimage == NULL || drawable->gimage->layers == NULL)
return;
if (GIMP_IS_LAYER (drawable))
base_list = drawable->gimage->layers;
else if (GIMP_IS_CHANNEL (drawable))
base_list = drawable->gimage->channels;
else
base_list = NULL;
for (list = base_list; list; list = g_slist_next (list))
{
drawable2 = GIMP_DRAWABLE (list->data);
if (drawable != drawable2 &&
strcmp (gimp_object_get_name (GIMP_OBJECT (drawable)),
gimp_object_get_name (GIMP_OBJECT (drawable2))) == 0)
{
ext = strrchr (GIMP_OBJECT (drawable)->name, '#');
if (ext)
{
gchar *ext_str;
unique_ext = atoi (ext + 1);
ext_str = g_strdup_printf ("%d", unique_ext);
/* check if the extension really is of the form "#<n>" */
if (! strcmp (ext_str, ext + 1))
{
*ext = '\0';
}
else
{
unique_ext = 0;
}
g_free (ext_str);
}
else
{
unique_ext = 0;
}
do
{
unique_ext++;
g_free (new_name);
new_name = g_strdup_printf ("%s#%d",
GIMP_OBJECT (drawable)->name,
unique_ext);
for (list2 = base_list; list2; list2 = g_slist_next (list2))
{
drawable2 = GIMP_DRAWABLE (list2->data);
if (drawable == drawable2)
continue;
if (! strcmp (GIMP_OBJECT (drawable2)->name, new_name))
{
break;
}
}
}
while (list2);
g_free (GIMP_OBJECT (drawable)->name);
GIMP_OBJECT (drawable)->name = new_name;
break;
}
}
}
/*
* Static variables
......@@ -358,100 +457,6 @@ gimp_drawable_visible (const GimpDrawable *drawable)
return drawable->visible;
}
const gchar *
gimp_drawable_get_name (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
return drawable->name;
}
void
gimp_drawable_set_name (GimpDrawable *drawable,
const gchar *name)
{
GSList *list, *listb, *base_list;
GimpDrawable *drawableb;
gint number = 1;
gchar *newname;
gchar *ext;
gchar numberbuf[20];
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (name != NULL);
if (drawable->name)
{
g_free (drawable->name);
drawable->name = NULL;
}
if (drawable->gimage == NULL || drawable->gimage->layers == NULL)
{
/* no other layers to check name against */
drawable->name = g_strdup (name);
return;
}
if (GIMP_IS_LAYER (drawable))
base_list = drawable->gimage->layers;
else if (GIMP_IS_CHANNEL (drawable))
base_list = drawable->gimage->channels;
else
base_list = NULL;
for (list = base_list; list; list = g_slist_next (list))
{
drawableb = GIMP_DRAWABLE (list->data);
if (drawable != drawableb &&
strcmp (name, gimp_drawable_get_name (drawableb)) == 0)
{ /* names conflict */
newname = g_malloc (strlen (name) + 10); /* if this aint enough
yer screwed */
strcpy (newname, name);
if ((ext = strrchr (newname, '#')))
{
number = atoi(ext+1);
/* Check if there really was the number we think after the # */
g_snprintf (numberbuf, sizeof (numberbuf), "#%d", number);
if (strcmp (ext, numberbuf) != 0)
{
/* No, so just ignore the # */
number = 1;
ext = &newname[strlen (newname)];
}
}
else
{
number = 1;
ext = &newname[strlen (newname)];
}
sprintf (ext, "#%d", number + 1);
listb = base_list;
while (listb) /* make sure the new name is unique */
{
drawableb = GIMP_DRAWABLE (listb->data);
if (drawable != drawableb &&
strcmp (newname, gimp_drawable_get_name (drawableb)) == 0)
{
number++;
sprintf (ext, "#%d", number+1);
/* Rescan from beginning */
listb = base_list;
continue;
}
listb = listb->next;
}
drawable->name = g_strdup (newname);
g_free (newname);
return;
}
}
drawable->name = g_strdup (name);
}
guchar *
gimp_drawable_get_color_at (GimpDrawable *drawable,
gint x,
......@@ -727,7 +732,6 @@ gimp_drawable_deallocate (GimpDrawable *drawable)
static void
gimp_drawable_init (GimpDrawable *drawable)
{
drawable->name = NULL;
drawable->tiles = NULL;
drawable->visible = FALSE;
drawable->width = 0;
......@@ -764,9 +768,6 @@ gimp_drawable_destroy (GtkObject *object)
drawable = GIMP_DRAWABLE (object);
g_hash_table_remove (gimp_drawable_table, (gpointer) drawable->ID);
if (drawable->name)
g_free (drawable->name);
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
......@@ -816,7 +817,6 @@ gimp_drawable_configure (GimpDrawable *drawable,
return;
}
drawable->name = NULL;
drawable->width = width;
drawable->height = height;
drawable->bytes = bpp;
......@@ -834,7 +834,7 @@ gimp_drawable_configure (GimpDrawable *drawable,
if (gimage)
gimp_drawable_set_gimage (drawable, gimage);
gimp_drawable_set_name (drawable, name);
gimp_object_set_name (GIMP_OBJECT (drawable), name);
/* preview variables */
drawable->preview_cache = NULL;
......
......@@ -36,7 +36,6 @@ struct _GimpDrawable
{
GimpObject data;
gchar *name; /* name of drawable */
TileManager *tiles; /* tiles for drawable data */
gboolean visible; /* controls visibility */
gint width, height; /* size of drawable */
......@@ -96,13 +95,11 @@ gint gimp_drawable_bytes (GimpDrawable *);
gint gimp_drawable_width (GimpDrawable *);
gint gimp_drawable_height (GimpDrawable *);
gboolean gimp_drawable_visible (const GimpDrawable *drawable);
void gimp_drawable_offsets (GimpDrawable *,
gint *, gint *);
void gimp_drawable_offsets (GimpDrawable *drawable,
gint *offset_x,
gint *offset_y);
guchar * gimp_drawable_cmap (const GimpDrawable *drawable);
const gchar * gimp_drawable_get_name (const GimpDrawable *drawable);
void gimp_drawable_set_name (GimpDrawable *drawable,
const gchar *name);
guchar * gimp_drawable_get_color_at (GimpDrawable *drawable,
gint x,
......@@ -133,4 +130,5 @@ void gimp_drawable_configure (GimpDrawable *drawable,
GimpImageType type,
const gchar *name);
#endif /* __GIMP_DRAWABLE_H__ */
......@@ -612,8 +612,8 @@ duplicate (GimpImage *gimage)
/* Make sure if the layer has a layer mask, it's name isn't screwed up */
if (new_layer->mask)
{
gimp_drawable_set_name(GIMP_DRAWABLE(new_layer->mask),
gimp_drawable_get_name(GIMP_DRAWABLE(layer->mask)));
gimp_object_set_name (GIMP_OBJECT (new_layer->mask),
gimp_object_get_name (GIMP_OBJECT (layer->mask)));
}
if (gimage->active_layer == layer)
......@@ -643,8 +643,8 @@ duplicate (GimpImage *gimage)
gimp_drawable_set_gimage(GIMP_DRAWABLE(new_channel), new_gimage);
/* Make sure the copied channel doesn't say: "<old channel> copy" */
gimp_drawable_set_name(GIMP_DRAWABLE(new_channel),
gimp_drawable_get_name(GIMP_DRAWABLE(channel)));
gimp_object_set_name (GIMP_OBJECT (new_channel),
gimp_object_get_name (GIMP_OBJECT (channel)));
if (gimage->active_channel == channel)
active_channel = (new_channel);
......
......@@ -839,7 +839,7 @@ gimp_image_apply_image (GimpImage *gimage,
/* determine what sort of operation is being attempted and
* if it's actually legal...
*/
operation = valid_combinations[drawable_type (drawable)][src2PR->bytes];
operation = valid_combinations[gimp_drawable_type (drawable)][src2PR->bytes];
if (operation == -1)
{
g_message ("gimp_image_apply_image sent illegal parameters");
......@@ -847,13 +847,13 @@ gimp_image_apply_image (GimpImage *gimage,
}
/* get the layer offsets */
drawable_offsets (drawable, &offset_x, &offset_y);
gimp_drawable_offsets (drawable, &offset_x, &offset_y);
/* make sure the image application coordinates are within gimage bounds */
x1 = CLAMP (x, 0, drawable_width (drawable));
y1 = CLAMP (y, 0, drawable_height (drawable));
x2 = CLAMP (x + src2PR->w, 0, drawable_width (drawable));
y2 = CLAMP (y + src2PR->h, 0, drawable_height (drawable));
x1 = CLAMP (x, 0, gimp_drawable_width (drawable));
y1 = CLAMP (y, 0, gimp_drawable_height (drawable));
x2 = CLAMP (x + src2PR->w, 0, gimp_drawable_width (drawable));
y2 = CLAMP (y + src2PR->h, 0, gimp_drawable_height (drawable));
if (mask)
{
......@@ -861,10 +861,10 @@ gimp_image_apply_image (GimpImage *gimage,
* we need to add the layer offset to transform coords
* into the mask coordinate system
*/
x1 = CLAMP (x1, -offset_x, drawable_width (GIMP_DRAWABLE (mask))-offset_x);
y1 = CLAMP (y1, -offset_y, drawable_height(GIMP_DRAWABLE (mask))-offset_y);
x2 = CLAMP (x2, -offset_x, drawable_width (GIMP_DRAWABLE (mask))-offset_x);
y2 = CLAMP (y2, -offset_y, drawable_height(GIMP_DRAWABLE (mask))-offset_y);
x1 = CLAMP (x1, -offset_x, gimp_drawable_width (GIMP_DRAWABLE (mask))-offset_x);
y1 = CLAMP (y1, -offset_y, gimp_drawable_height(GIMP_DRAWABLE (mask))-offset_y);
x2 = CLAMP (x2, -offset_x, gimp_drawable_width (GIMP_DRAWABLE (mask))-offset_x);
y2 = CLAMP (y2, -offset_y, gimp_drawable_height(GIMP_DRAWABLE (mask))-offset_y);
}
/* If the calling procedure specified an undo step... */
......@@ -878,9 +878,9 @@ gimp_image_apply_image (GimpImage *gimage,
pixel_region_init (&src1PR, src1_tiles,
x1, y1, (x2 - x1), (y2 - y1), FALSE);
else
pixel_region_init (&src1PR, drawable_data (drawable),
pixel_region_init (&src1PR, gimp_drawable_data (drawable),
x1, y1, (x2 - x1), (y2 - y1), FALSE);
pixel_region_init (&destPR, drawable_data (drawable),
pixel_region_init (&destPR, gimp_drawable_data (drawable),
x1, y1, (x2 - x1), (y2 - y1), TRUE);
pixel_region_resize (src2PR,
src2PR->x + (x1 - x), src2PR->y + (y1 - y),
......@@ -898,7 +898,7 @@ gimp_image_apply_image (GimpImage *gimage,
my = y1 + offset_y;
pixel_region_init (&maskPR,
drawable_data (GIMP_DRAWABLE(mask)),
gimp_drawable_data (GIMP_DRAWABLE (mask)),
mx, my,
(x2 - x1), (y2 - y1),
FALSE);
......@@ -946,7 +946,7 @@ gimp_image_replace_image (GimpImage *gimage,
/* determine what sort of operation is being attempted and
* if it's actually legal...
*/
operation = valid_combinations [drawable_type (drawable)][src2PR->bytes];
operation = valid_combinations [gimp_drawable_type (drawable)][src2PR->bytes];
if (operation == -1)
{
g_message ("gimp_image_apply_image sent illegal parameters");
......@@ -954,13 +954,13 @@ gimp_image_replace_image (GimpImage *gimage,
}
/* get the layer offsets */
drawable_offsets (drawable, &offset_x, &offset_y);
gimp_drawable_offsets (drawable, &offset_x, &offset_y);
/* make sure the image application coordinates are within gimage bounds */
x1 = CLAMP (x, 0, drawable_width (drawable));
y1 = CLAMP (y, 0, drawable_height (drawable));
x2 = CLAMP (x + src2PR->w, 0, drawable_width (drawable));
y2 = CLAMP (y + src2PR->h, 0, drawable_height (drawable));
x1 = CLAMP (x, 0, gimp_drawable_width (drawable));
y1 = CLAMP (y, 0, gimp_drawable_height (drawable));
x2 = CLAMP (x + src2PR->w, 0, gimp_drawable_width (drawable));