Commit dfd7df9a authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added new functions gimp_image_active_[layer|channel|vectors]_changed()

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

	* app/core/gimpimage.[ch]: added new functions
	gimp_image_active_[layer|channel|vectors]_changed() which emit the
	resp. signals.

	* app/core/gimpimage-undo-push.c (undo_pop_layer,channel,vectors):
	fixed them to not leave the image's active layer, channel, vectors
	pointers undefined (fixes bug #109110). Call gimp_item_removed()
	from all of them.

	* app/core/gimpimage-qmask.c: cleanup.
parent b7190b25
2003-03-25 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage.[ch]: added new functions
gimp_image_active_[layer|channel|vectors]_changed() which emit the
resp. signals.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel,vectors):
fixed them to not leave the image's active layer, channel, vectors
pointers undefined (fixes bug #109110). Call gimp_item_removed()
from all of them.
* app/core/gimpimage-qmask.c: cleanup.
2003-03-25 Michael Natterer <mitch@gimp.org>
* app/app_procs.c (app_init): cast batch_cmds to (const gchar **)
......@@ -51,102 +51,99 @@ void
gimp_image_set_qmask_state (GimpImage *gimage,
gboolean qmask_state)
{
GimpChannel *mask;
GimpRGB color;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
if (qmask_state != gimage->qmask_state)
if (qmask_state == gimage->qmask_state)
return;
if (qmask_state)
{
GimpChannel *mask;
GimpRGB color;
/* Set the defaults */
color = gimage->qmask_color;
if (qmask_state)
{
/* Set the defaults */
color = gimage->qmask_color;
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
if (! mask)
{
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
_("Enable QuickMask"));
if (! mask)
if (gimp_image_mask_is_empty (gimage)) /* if no selection */
{
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
_("Enable QuickMask"));
GimpLayer *layer;
if (gimp_image_mask_is_empty (gimage))
if ((layer = gimp_image_floating_sel (gimage)))
{
GimpLayer *layer;
/* if no selection */
if ((layer = gimp_image_floating_sel (gimage)))
{
floating_sel_to_layer (layer);
}
floating_sel_to_layer (layer);
}
mask = gimp_channel_new (gimage,
gimage->width,
gimage->height,
"Qmask",
&color);
gimp_image_add_channel (gimage, mask, 0);
mask = gimp_channel_new (gimage,
gimage->width,
gimage->height,
"Qmask",
&color);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (mask),
gimp_get_current_context (gimage->gimp),
GIMP_TRANSPARENT_FILL);
}
else /* if selection */
{
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
FALSE));
gimp_image_mask_clear (gimage, NULL); /* Clear the selection */
gimp_drawable_fill_by_type (GIMP_DRAWABLE (mask),
gimp_get_current_context (gimage->gimp),
GIMP_TRANSPARENT_FILL);
}
else /* if selection */
{
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
FALSE));
gimp_image_mask_clear (gimage, NULL); /* Clear the selection */
gimp_channel_set_color (mask, &color, FALSE);
gimp_item_rename (GIMP_ITEM (mask), "Qmask");
gimp_channel_set_color (mask, &color, FALSE);
gimp_item_rename (GIMP_ITEM (mask), "Qmask");
}
gimp_image_add_channel (gimage, mask, 0);
}
gimp_image_add_channel (gimage, mask, 0);
if (gimage->qmask_inverted)
gimp_channel_invert (mask, TRUE);
if (gimage->qmask_inverted)
gimp_channel_invert (mask, TRUE);
gimp_image_undo_push_image_qmask (gimage, NULL);
gimp_image_undo_push_image_qmask (gimage, NULL);
gimp_image_undo_group_end (gimage);
gimp_image_undo_group_end (gimage);
/* connect to the removed signal, so the buttons get updated */
g_signal_connect (mask, "removed",
G_CALLBACK (gimp_image_qmask_removed_callback),
gimage);
}
/* connect to the removed signal, so the buttons get updated */
g_signal_connect (mask, "removed",
G_CALLBACK (gimp_image_qmask_removed_callback),
gimage);
}
else
{
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
}
else
{
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
if (mask)
{
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
_("Disable QuickMask"));
if (mask)
{
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
_("Disable QuickMask"));
/* push the undo here since removing the mask will
* call the qmask_removed_callback() which will set
* the qmask_state to FALSE
*/
gimp_image_undo_push_image_qmask (gimage, NULL);
/* push the undo here since removing the mask will
* call the qmask_removed_callback() which will set
* the qmask_state to FALSE
*/
gimp_image_undo_push_image_qmask (gimage, NULL);
if (gimage->qmask_inverted)
gimp_channel_invert (mask, TRUE);
if (gimage->qmask_inverted)
gimp_channel_invert (mask, TRUE);
gimp_image_mask_load (gimage, mask);
gimp_image_remove_channel (gimage, mask);
gimp_image_mask_load (gimage, mask);
gimp_image_remove_channel (gimage, mask);
gimp_image_undo_group_end (gimage);
}
gimp_image_undo_group_end (gimage);
}
}
gimage->qmask_state = qmask_state ? TRUE : FALSE;
gimage->qmask_state = qmask_state ? TRUE : FALSE;
gimp_image_qmask_changed (gimage);
}
gimp_image_qmask_changed (gimage);
}
gboolean
......
......@@ -51,102 +51,99 @@ void
gimp_image_set_qmask_state (GimpImage *gimage,
gboolean qmask_state)
{
GimpChannel *mask;
GimpRGB color;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
if (qmask_state != gimage->qmask_state)
if (qmask_state == gimage->qmask_state)
return;
if (qmask_state)
{
GimpChannel *mask;
GimpRGB color;
/* Set the defaults */
color = gimage->qmask_color;
if (qmask_state)
{
/* Set the defaults */
color = gimage->qmask_color;
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
if (! mask)
{
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
_("Enable QuickMask"));
if (! mask)
if (gimp_image_mask_is_empty (gimage)) /* if no selection */
{
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
_("Enable QuickMask"));
GimpLayer *layer;
if (gimp_image_mask_is_empty (gimage))
if ((layer = gimp_image_floating_sel (gimage)))
{
GimpLayer *layer;
/* if no selection */
if ((layer = gimp_image_floating_sel (gimage)))
{
floating_sel_to_layer (layer);
}
floating_sel_to_layer (layer);
}
mask = gimp_channel_new (gimage,
gimage->width,
gimage->height,
"Qmask",
&color);
gimp_image_add_channel (gimage, mask, 0);
mask = gimp_channel_new (gimage,
gimage->width,
gimage->height,
"Qmask",
&color);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (mask),
gimp_get_current_context (gimage->gimp),
GIMP_TRANSPARENT_FILL);
}
else /* if selection */
{
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
FALSE));
gimp_image_mask_clear (gimage, NULL); /* Clear the selection */
gimp_drawable_fill_by_type (GIMP_DRAWABLE (mask),
gimp_get_current_context (gimage->gimp),
GIMP_TRANSPARENT_FILL);
}
else /* if selection */
{
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (gimp_image_get_mask (gimage)),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
FALSE));
gimp_image_mask_clear (gimage, NULL); /* Clear the selection */
gimp_channel_set_color (mask, &color, FALSE);
gimp_item_rename (GIMP_ITEM (mask), "Qmask");
gimp_channel_set_color (mask, &color, FALSE);
gimp_item_rename (GIMP_ITEM (mask), "Qmask");
}
gimp_image_add_channel (gimage, mask, 0);
}
gimp_image_add_channel (gimage, mask, 0);
if (gimage->qmask_inverted)
gimp_channel_invert (mask, TRUE);
if (gimage->qmask_inverted)
gimp_channel_invert (mask, TRUE);
gimp_image_undo_push_image_qmask (gimage, NULL);
gimp_image_undo_push_image_qmask (gimage, NULL);
gimp_image_undo_group_end (gimage);
gimp_image_undo_group_end (gimage);
/* connect to the removed signal, so the buttons get updated */
g_signal_connect (mask, "removed",
G_CALLBACK (gimp_image_qmask_removed_callback),
gimage);
}
/* connect to the removed signal, so the buttons get updated */
g_signal_connect (mask, "removed",
G_CALLBACK (gimp_image_qmask_removed_callback),
gimage);
}
else
{
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
}
else
{
mask = gimp_image_get_channel_by_name (gimage, "Qmask");
if (mask)
{
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
_("Disable QuickMask"));
if (mask)
{
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_QMASK,
_("Disable QuickMask"));
/* push the undo here since removing the mask will
* call the qmask_removed_callback() which will set
* the qmask_state to FALSE
*/
gimp_image_undo_push_image_qmask (gimage, NULL);
/* push the undo here since removing the mask will
* call the qmask_removed_callback() which will set
* the qmask_state to FALSE
*/
gimp_image_undo_push_image_qmask (gimage, NULL);
if (gimage->qmask_inverted)
gimp_channel_invert (mask, TRUE);
if (gimage->qmask_inverted)
gimp_channel_invert (mask, TRUE);
gimp_image_mask_load (gimage, mask);
gimp_image_remove_channel (gimage, mask);
gimp_image_mask_load (gimage, mask);
gimp_image_remove_channel (gimage, mask);
gimp_image_undo_group_end (gimage);
}
gimp_image_undo_group_end (gimage);
}
}
gimage->qmask_state = qmask_state ? TRUE : FALSE;
gimage->qmask_state = qmask_state ? TRUE : FALSE;
gimp_image_qmask_changed (gimage);
}
gimp_image_qmask_changed (gimage);
}
gboolean
......
......@@ -1254,15 +1254,26 @@ undo_pop_layer (GimpUndo *undo,
/* record the current position */
lu->prev_position = gimp_image_get_layer_index (undo->gimage, layer);
/* if exists, set the previous layer */
if (lu->prev_layer)
gimp_image_set_active_layer (undo->gimage, lu->prev_layer);
if (layer == gimp_image_get_active_layer (undo->gimage))
{
if (lu->prev_layer)
{
gimp_image_set_active_layer (undo->gimage, lu->prev_layer);
}
else
{
undo->gimage->active_layer = NULL;
gimp_image_active_layer_changed (undo->gimage);
}
}
/* remove the layer */
gimp_container_remove (undo->gimage->layers, GIMP_OBJECT (layer));
undo->gimage->layer_stack = g_slist_remove (undo->gimage->layer_stack,
layer);
gimp_item_removed (GIMP_ITEM (layer));
/* reset the gimage values */
if (gimp_layer_is_floating_sel (layer))
{
......@@ -2033,9 +2044,15 @@ undo_pop_channel (GimpUndo *undo,
/* remove the channel */
gimp_container_remove (undo->gimage->channels, GIMP_OBJECT (channel));
/* if exists, set the previous channel */
if (cu->prev_channel)
gimp_image_set_active_channel (undo->gimage, cu->prev_channel);
gimp_item_removed (GIMP_ITEM (channel));
if (channel == gimp_image_get_active_channel (undo->gimage))
{
if (cu->prev_channel)
gimp_image_set_active_channel (undo->gimage, cu->prev_channel);
else
gimp_image_unset_active_channel (undo->gimage);
}
/* update the area */
gimp_drawable_update (GIMP_DRAWABLE (channel),
......@@ -2053,8 +2070,6 @@ undo_pop_channel (GimpUndo *undo,
/* add the new channel */
gimp_container_insert (undo->gimage->channels,
GIMP_OBJECT (channel), cu->prev_position);
/* set the new channel */
gimp_image_set_active_channel (undo->gimage, channel);
/* update the area */
......@@ -2450,9 +2465,20 @@ undo_pop_vectors (GimpUndo *undo,
/* remove the vectors */
gimp_container_remove (undo->gimage->vectors, GIMP_OBJECT (vectors));
/* if exists, set the previous vectors */
if (vu->prev_vectors)
gimp_image_set_active_vectors (undo->gimage, vu->prev_vectors);
gimp_item_removed (GIMP_ITEM (vectors));
if (vectors == gimp_image_get_active_vectors (undo->gimage))
{
if (vu->prev_vectors)
{
gimp_image_set_active_vectors (undo->gimage, vu->prev_vectors);
}
else
{
undo->gimage->active_vectors = NULL;
gimp_image_active_vectors_changed (undo->gimage);
}
}
}
else
{
......@@ -2463,9 +2489,7 @@ undo_pop_vectors (GimpUndo *undo,
/* add the new vectors */
gimp_container_insert (undo->gimage->vectors,
GIMP_OBJECT (vectors), vu->prev_position);
/* set the new vectors */
GIMP_OBJECT (vectors), vu->prev_position);
gimp_image_set_active_vectors (undo->gimage, vectors);
}
......
......@@ -2248,6 +2248,30 @@ gimp_image_set_active_vectors (GimpImage *gimage,
return vectors;
}
void
gimp_image_active_layer_changed (GimpImage *gimage)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_signal_emit (gimage, gimp_image_signals[ACTIVE_LAYER_CHANGED], 0);
}
void
gimp_image_active_channel_changed (GimpImage *gimage)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_signal_emit (gimage, gimp_image_signals[ACTIVE_CHANNEL_CHANGED], 0);
}
void
gimp_image_active_vectors_changed (GimpImage *gimage)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_signal_emit (gimage, gimp_image_signals[ACTIVE_VECTORS_CHANGED], 0);
}
gint
gimp_image_get_layer_index (const GimpImage *gimage,
const GimpLayer *layer)
......@@ -2548,7 +2572,6 @@ gimp_image_remove_layer (GimpImage *gimage,
else
{
gimage->active_layer = NULL;
g_signal_emit (gimage, gimp_image_signals[ACTIVE_LAYER_CHANGED], 0);
}
}
......@@ -3026,7 +3049,6 @@ gimp_image_remove_vectors (GimpImage *gimage,
else
{
gimage->active_vectors = NULL;
g_signal_emit (gimage, gimp_image_signals[ACTIVE_VECTORS_CHANGED], 0);
}
}
......
......@@ -402,6 +402,10 @@ GimpChannel * gimp_image_unset_active_channel (GimpImage *gimage);
GimpVectors * gimp_image_set_active_vectors (GimpImage *gimage,
GimpVectors *vectors);
void gimp_image_active_layer_changed (GimpImage *gimage);
void gimp_image_active_channel_changed (GimpImage *gimage);
void gimp_image_active_vectors_changed (GimpImage *gimage);
gint gimp_image_get_layer_index (const GimpImage *gimage,
const GimpLayer *layer);
gint gimp_image_get_channel_index (const GimpImage *gimage,
......
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