layers-commands.c 33.3 KB
Newer Older
Michael Natterer's avatar
Michael Natterer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

#include <string.h> 

#include <gtk/gtk.h>

#include "libgimpmath/gimpmath.h"
26
#include "libgimpbase/gimpbase.h"
Michael Natterer's avatar
Michael Natterer committed
27 28
#include "libgimpwidgets/gimpwidgets.h"

29
#include "gui-types.h"
Michael Natterer's avatar
Michael Natterer committed
30

Michael Natterer's avatar
Michael Natterer committed
31
#include "core/gimp.h"
32
#include "core/gimpcontext.h"
33 34
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
35
#include "core/gimpimage-merge.h"
36
#include "core/gimplayer.h"
Michael Natterer's avatar
Michael Natterer committed
37
#include "core/gimplayer-floating-sel.h"
38 39 40
#include "core/gimplayermask.h"
#include "core/gimplist.h"

41 42
#include "pdb/procedural_db.h"

43
#include "widgets/gimpenummenu.h"
44
#include "widgets/gimpitemfactory.h"
Michael Natterer's avatar
Michael Natterer committed
45 46
#include "widgets/gimpwidgets-utils.h"

Michael Natterer's avatar
Michael Natterer committed
47
#include "layers-commands.h"
Michael Natterer's avatar
Michael Natterer committed
48
#include "resize-dialog.h"
Michael Natterer's avatar
Michael Natterer committed
49 50 51 52 53 54

#include "undo.h"

#include "libgimp/gimpintl.h"


55 56
/*  local function prototypes  */

57 58 59 60 61
static void   layers_add_mask_query       (GimpLayer *layer);
static void   layers_scale_layer_query    (GimpImage *gimage,
					   GimpLayer *layer);
static void   layers_resize_layer_query   (GimpImage *gimage,
					   GimpLayer *layer);
Michael Natterer's avatar
Michael Natterer committed
62 63


64 65
#define return_if_no_image(gimage) \
  gimage = (GimpImage *) gimp_widget_get_callback_context (widget); \
66
  if (! GIMP_IS_IMAGE (gimage)) \
67 68 69 70
    gimage = gimp_context_get_image (gimp_get_user_context (GIMP (data))); \
  if (! gimage) \
    return

71 72 73 74 75 76
#define return_if_no_layer(gimage,layer) \
  return_if_no_image (gimage); \
  layer = gimp_image_get_active_layer (gimage); \
  if (! layer) \
    return

77

78 79
/*  public functions  */

Michael Natterer's avatar
Michael Natterer committed
80 81 82 83 84 85 86
void
layers_previous_cmd_callback (GtkWidget *widget,
			      gpointer   data)
{
  GimpImage *gimage;
  GimpLayer *new_layer;
  gint       current_layer;
87
  return_if_no_image (gimage);
Michael Natterer's avatar
Michael Natterer committed
88 89 90 91 92 93 94 95 96 97 98 99

  current_layer =
    gimp_image_get_layer_index (gimage, gimp_image_get_active_layer (gimage));

  if (current_layer > 0)
    {
      new_layer = (GimpLayer *)
	gimp_container_get_child_by_index (gimage->layers, current_layer - 1);

      if (new_layer)
	{
	  gimp_image_set_active_layer (gimage, new_layer);
100
	  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
101 102 103 104 105 106 107 108 109 110 111
	}
    }
}

void
layers_next_cmd_callback (GtkWidget *widget,
			  gpointer   data)
{
  GimpImage *gimage;
  GimpLayer *new_layer;
  gint       current_layer;
112
  return_if_no_image (gimage);
Michael Natterer's avatar
Michael Natterer committed
113 114 115 116 117 118 119 120 121 122 123

  current_layer =
    gimp_image_get_layer_index (gimage, gimp_image_get_active_layer (gimage));

  new_layer = 
    GIMP_LAYER (gimp_container_get_child_by_index (gimage->layers, 
						   current_layer + 1));

  if (new_layer)
    {
      gimp_image_set_active_layer (gimage, new_layer);
124
      gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
125 126 127 128 129 130 131 132
    }
}

void
layers_raise_cmd_callback (GtkWidget *widget,
			   gpointer   data)
{
  GimpImage *gimage;
133 134
  GimpLayer *active_layer;
  return_if_no_layer (gimage,active_layer);
Michael Natterer's avatar
Michael Natterer committed
135

136
  gimp_image_raise_layer (gimage, active_layer);
137
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
138 139 140 141 142 143 144
}

void
layers_lower_cmd_callback (GtkWidget *widget,
			   gpointer   data)
{
  GimpImage *gimage;
145 146
  GimpLayer *active_layer;
  return_if_no_layer (gimage,active_layer);
Michael Natterer's avatar
Michael Natterer committed
147

148
  gimp_image_lower_layer (gimage, active_layer);
149
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
150 151 152 153 154 155 156
}

void
layers_raise_to_top_cmd_callback (GtkWidget *widget,
				  gpointer   data)
{
  GimpImage *gimage;
157 158
  GimpLayer *active_layer;
  return_if_no_layer (gimage,active_layer);
Michael Natterer's avatar
Michael Natterer committed
159

160
  gimp_image_raise_layer_to_top (gimage, active_layer);
161
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
162 163 164 165 166 167 168
}

void
layers_lower_to_bottom_cmd_callback (GtkWidget *widget,
				     gpointer   data)
{
  GimpImage *gimage;
169 170
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
171

172
  gimp_image_lower_layer_to_bottom (gimage, active_layer);
173
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
174 175 176 177 178 179 180
}

void
layers_new_cmd_callback (GtkWidget *widget,
			 gpointer   data)
{
  GimpImage *gimage;
181
  return_if_no_image (gimage);
Michael Natterer's avatar
Michael Natterer committed
182

183
  layers_new_layer_query (gimage, NULL);
Michael Natterer's avatar
Michael Natterer committed
184 185 186 187 188 189 190 191 192
}

void
layers_duplicate_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
  GimpImage *gimage;
  GimpLayer *active_layer;
  GimpLayer *new_layer;
193
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
194

195 196 197
  new_layer = gimp_layer_copy (active_layer,
                               G_TYPE_FROM_INSTANCE (active_layer),
                               TRUE);
Michael Natterer's avatar
Michael Natterer committed
198 199
  gimp_image_add_layer (gimage, new_layer, -1);

200
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
201 202 203
}

void
204
layers_anchor_cmd_callback (GtkWidget *widget,
Michael Natterer's avatar
Michael Natterer committed
205 206 207
			    gpointer   data)
{
  GimpImage *gimage;
208 209
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
210

211
  layers_anchor_layer (active_layer);
212
}
Michael Natterer's avatar
Michael Natterer committed
213

214 215 216 217 218
void
layers_merge_down_cmd_callback (GtkWidget *widget,
				gpointer   data)
{
  GimpImage *gimage;
219 220
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
221

222
  gimp_image_merge_down (gimage, active_layer, GIMP_EXPAND_AS_NECESSARY);
223
  gimp_image_flush (gimage);
224 225
}

226 227 228 229 230
void
layers_delete_cmd_callback (GtkWidget *widget,
			    gpointer   data)
{
  GimpImage *gimage;
231 232
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
233

234 235
  if (gimp_layer_is_floating_sel (active_layer))
    floating_sel_remove (active_layer);
Michael Natterer's avatar
Michael Natterer committed
236
  else
237
    gimp_image_remove_layer (gimage, active_layer);
238

239
  gimp_image_flush (gimage);
240 241 242
}

void
243 244
layers_resize_cmd_callback (GtkWidget *widget,
			    gpointer   data)
245 246
{
  GimpImage *gimage;
247 248
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
249

250
  layers_resize_layer_query (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
251 252 253
}

void
254 255
layers_resize_to_image_cmd_callback (GtkWidget *widget,
				     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
256 257
{
  GimpImage *gimage;
258 259
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
260 261
  
  gimp_layer_resize_to_image (active_layer);
262
  gimp_image_flush (gimage);
263
}
Michael Natterer's avatar
Michael Natterer committed
264

265 266 267 268 269 270 271 272 273
void
layers_scale_cmd_callback (GtkWidget *widget,
			   gpointer   data)
{
  GimpImage *gimage;
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);

  layers_scale_layer_query (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
274 275 276
}

void
277 278
layers_crop_cmd_callback (GtkWidget *widget,
                          gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
279 280
{
  GimpImage *gimage;
281
  GimpLayer *active_layer;
282 283
  gint       x1, y1, x2, y2;
  gint       off_x, off_y;
284
  return_if_no_layer (gimage, active_layer);
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308

  if (! gimp_image_mask_bounds (gimage, &x1, &y1, &x2, &y2))
    {
      g_message (_("Cannot crop because the current selection is empty."));
      return;
    }

  gimp_drawable_offsets (GIMP_DRAWABLE (active_layer), &off_x, &off_y);

  off_x -= x1;
  off_y -= y1;

  undo_push_group_start (gimage, LAYER_RESIZE_UNDO_GROUP);

  if (gimp_layer_is_floating_sel (active_layer))
    floating_sel_relax (active_layer, TRUE);

  gimp_layer_resize (active_layer, x2 - x1, y2 - y1, off_x, off_y);

  if (gimp_layer_is_floating_sel (active_layer))
    floating_sel_rigor (active_layer, TRUE);

  undo_push_group_end (gimage);

309
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
310 311 312 313 314 315 316
}

void
layers_add_layer_mask_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
  GimpImage *gimage;
317 318
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
319

320
  layers_add_mask_query (active_layer);
Michael Natterer's avatar
Michael Natterer committed
321 322 323 324 325 326 327
}

void
layers_apply_layer_mask_cmd_callback (GtkWidget *widget,
				      gpointer   data)
{
  GimpImage *gimage;
328 329
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
330

331
  if (gimp_layer_get_mask (active_layer))
Michael Natterer's avatar
Michael Natterer committed
332
    {
333 334 335
      gboolean flush;

      flush = ! active_layer->mask->apply_mask || active_layer->mask->show_mask;
Michael Natterer's avatar
Michael Natterer committed
336

337
      gimp_layer_apply_mask (active_layer, GIMP_MASK_APPLY, TRUE);
Michael Natterer's avatar
Michael Natterer committed
338 339

      if (flush)
340
        gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
341 342 343 344 345 346 347 348
    }
}

void
layers_delete_layer_mask_cmd_callback (GtkWidget *widget,
				       gpointer   data)
{
  GimpImage *gimage;
349 350
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
351

352
  if (gimp_layer_get_mask (active_layer))
Michael Natterer's avatar
Michael Natterer committed
353
    {
354
      gboolean flush;
Michael Natterer's avatar
Michael Natterer committed
355

356 357
      flush = active_layer->mask->apply_mask || active_layer->mask->show_mask;

358
      gimp_layer_apply_mask (active_layer, GIMP_MASK_DISCARD, TRUE);
Michael Natterer's avatar
Michael Natterer committed
359 360

      if (flush)
361
        gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
362 363 364 365
    }
}

void
366 367
layers_mask_select_cmd_callback (GtkWidget *widget,
				 gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
368 369
{
  GimpImage *gimage;
370 371
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
372

373 374 375
  if (gimp_layer_get_mask (active_layer))
    {
      gimp_image_mask_layer_mask (gimage, active_layer);
376
      gimp_image_flush (gimage);
377
    }
Michael Natterer's avatar
Michael Natterer committed
378 379 380
}

void
381 382
layers_alpha_select_cmd_callback (GtkWidget *widget,
				  gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
383 384
{
  GimpImage *gimage;
385 386
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
387

388
  gimp_image_mask_layer_alpha (gimage, active_layer);
389
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
390 391 392 393 394 395 396
}

void
layers_add_alpha_channel_cmd_callback (GtkWidget *widget,
				       gpointer   data)
{
  GimpImage *gimage;
397 398
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
399

400 401 402
  if (! gimp_drawable_has_alpha (GIMP_DRAWABLE (active_layer)))
    {
      gimp_layer_add_alpha (active_layer);
403
      gimp_image_flush (gimage);
404
    }
Michael Natterer's avatar
Michael Natterer committed
405 406 407 408 409 410 411
}

void
layers_edit_attributes_cmd_callback (GtkWidget *widget,
				     gpointer   data)
{
  GimpImage *gimage;
412 413
  GimpLayer *active_layer;
  return_if_no_layer (gimage, active_layer);
Michael Natterer's avatar
Michael Natterer committed
414

415
  layers_edit_layer_query (active_layer);
Michael Natterer's avatar
Michael Natterer committed
416 417
}

418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
void
layers_remove_layer (GimpImage *gimage,
                     GimpLayer *layer)
{
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
  g_return_if_fail (GIMP_IS_LAYER (layer));

  if (gimp_layer_is_floating_sel (layer))
    floating_sel_remove (layer);
  else
    gimp_image_remove_layer (gimage, layer);
}

void
layers_anchor_layer (GimpLayer *layer)
{
  g_return_if_fail (GIMP_IS_LAYER (layer));

  if (gimp_layer_is_floating_sel (layer))
    {
      floating_sel_anchor (layer);
439
      gimp_image_flush (gimp_item_get_image (GIMP_ITEM (layer)));
440 441 442
    }
}

Michael Natterer's avatar
Michael Natterer committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462

/********************************/
/*  The new layer query dialog  */
/********************************/

typedef struct _NewLayerOptions NewLayerOptions;

struct _NewLayerOptions
{
  GtkWidget    *query_box;
  GtkWidget    *name_entry;
  GtkWidget    *size_se;

  GimpFillType  fill_type;
  gint          xsize;
  gint          ysize;

  GimpImage    *gimage;
};

463
static GimpFillType  fill_type  = GIMP_TRANSPARENT_FILL;
Michael Natterer's avatar
Michael Natterer committed
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
static gchar        *layer_name = NULL;

static void
new_layer_query_ok_callback (GtkWidget *widget,
			     gpointer   data)
{
  NewLayerOptions *options;
  GimpLayer       *layer;
  GimpImage       *gimage;

  options = (NewLayerOptions *) data;

  if (layer_name)
    g_free (layer_name);
  layer_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry)));

  options->xsize = 
    RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (options->size_se), 0));
  options->ysize =
    RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (options->size_se), 1));

  fill_type = options->fill_type;

  if ((gimage = options->gimage))
    {
489 490 491
      layer = gimp_layer_new (gimage,
                              options->xsize,
                              options->ysize,
Michael Natterer's avatar
Michael Natterer committed
492
			      gimp_image_base_type_with_alpha (gimage),
493 494
			      layer_name,
                              GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
Michael Natterer's avatar
Michael Natterer committed
495 496
      if (layer) 
	{
Michael Natterer's avatar
Michael Natterer committed
497 498 499
	  gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer),
				      gimp_get_user_context (gimage->gimp),
				      fill_type);
Michael Natterer's avatar
Michael Natterer committed
500 501
	  gimp_image_add_layer (gimage, layer, -1);
	  
502
          gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
503 504 505 506 507 508 509 510 511 512 513 514
	} 
      else 
	{
	  g_message ("new_layer_query_ok_callback():\n"
		     "could not allocate new layer");
	}
    }

  gtk_widget_destroy (options->query_box);
}

void
515 516
layers_new_layer_query (GimpImage *gimage,
                        GimpLayer *template)
Michael Natterer's avatar
Michael Natterer committed
517 518
{
  NewLayerOptions *options;
519
  GimpLayer       *floating_sel;
Michael Natterer's avatar
Michael Natterer committed
520 521 522 523 524 525
  GtkWidget       *vbox;
  GtkWidget       *table;
  GtkWidget       *label;
  GtkObject       *adjustment;
  GtkWidget       *spinbutton;
  GtkWidget       *frame;
526
  GtkWidget       *button;
Michael Natterer's avatar
Michael Natterer committed
527

528
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
529
  g_return_if_fail (! template || GIMP_IS_LAYER (template));
530 531 532 533 534 535 536

  /*  If there is a floating selection, the new command transforms
   *  the current fs into a new layer
   */
  if ((floating_sel = gimp_image_floating_sel (gimage)))
    {
      floating_sel_to_layer (floating_sel);
537
      gimp_image_flush (gimage);
538 539 540
      return;
    }

541 542 543 544 545 546 547 548 549 550
  if (template)
    {
      GimpLayer *new_layer;
      gint       width, height;
      gint       off_x, off_y;

      width  = gimp_drawable_width  (GIMP_DRAWABLE (template));
      height = gimp_drawable_height (GIMP_DRAWABLE (template));
      gimp_drawable_offsets (GIMP_DRAWABLE (template), &off_x, &off_y);

Michael Natterer's avatar
Michael Natterer committed
551
      undo_push_group_start (gimage, EDIT_PASTE_UNDO_GROUP);
552

553 554 555
      new_layer = gimp_layer_new (gimage,
                                  width,
                                  height,
556 557 558 559 560 561 562
                                  gimp_image_base_type_with_alpha (gimage),
                                  _("Empty Layer Copy"),
                                  template->opacity,
                                  template->mode);

      gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_layer),
                                  gimp_get_user_context (gimage->gimp),
563
                                  GIMP_TRANSPARENT_FILL);
564 565 566 567 568
      gimp_layer_translate (new_layer, off_x, off_y);
      gimp_image_add_layer (gimage, new_layer, -1);

      undo_push_group_end (gimage);

569
      gimp_image_flush (gimage);
570 571 572
      return;
    }

573 574
  options = g_new0 (NewLayerOptions, 1);

Michael Natterer's avatar
Michael Natterer committed
575 576 577 578 579 580 581 582 583 584 585
  options->fill_type = fill_type;
  options->gimage    = gimage;

  /*  The dialog  */
  options->query_box =
    gimp_dialog_new (_("New Layer Options"), "new_layer_options",
		     gimp_standard_help_func,
		     "dialogs/layers/new_layer.html",
		     GTK_WIN_POS_MOUSE,
		     FALSE, TRUE, FALSE,

586
		     GTK_STOCK_CANCEL, gtk_widget_destroy,
Michael Natterer's avatar
Michael Natterer committed
587 588
		     NULL, 1, NULL, FALSE, TRUE,

589 590 591
		     GTK_STOCK_OK, new_layer_query_ok_callback,
		     options, NULL, NULL, TRUE, FALSE,

Michael Natterer's avatar
Michael Natterer committed
592 593
		     NULL);

594 595 596
  g_object_weak_ref (G_OBJECT (options->query_box),
		     (GWeakNotify) g_free,
		     options);
Michael Natterer's avatar
Michael Natterer committed
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616

  /*  The main vbox  */
  vbox = gtk_vbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
		     vbox);

  table = gtk_table_new (3, 2, FALSE);
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);

  /*  The name label and entry  */
  label = gtk_label_new (_("Layer Name:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 1);
  gtk_widget_show (label);

  options->name_entry = gtk_entry_new ();
617
  gtk_widget_set_size_request (options->name_entry, 75, -1);
Michael Natterer's avatar
Michael Natterer committed
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
  gtk_table_attach_defaults (GTK_TABLE (table), 
			     options->name_entry, 1, 2, 0, 1);
  gtk_entry_set_text (GTK_ENTRY (options->name_entry),
		      (layer_name ? layer_name : _("New Layer")));
  gtk_widget_show (options->name_entry);

  /*  The size labels  */
  label = gtk_label_new (_("Layer Width:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
  gtk_widget_show (label);

  label = gtk_label_new (_("Height:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
  gtk_widget_show (label);

  /*  The size sizeentry  */
  adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 1);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 2);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
641
  gtk_widget_set_size_request (spinbutton, 75, -1);
Michael Natterer's avatar
Michael Natterer committed
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
  
  options->size_se = gimp_size_entry_new (1, gimage->unit, "%a",
					  TRUE, TRUE, FALSE, 75,
					  GIMP_SIZE_ENTRY_UPDATE_SIZE);
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (options->size_se),
                             GTK_SPIN_BUTTON (spinbutton), NULL);
  gtk_table_attach_defaults (GTK_TABLE (options->size_se), spinbutton,
                             1, 2, 0, 1);
  gtk_widget_show (spinbutton);
  gtk_table_attach (GTK_TABLE (table), options->size_se, 1, 2, 1, 3,
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (options->size_se);

  gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (options->size_se), 
			    GIMP_UNIT_PIXEL);

  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (options->size_se), 0,
                                  gimage->xresolution, FALSE);
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (options->size_se), 1,
                                  gimage->yresolution, FALSE);

  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (options->size_se), 0,
                                         GIMP_MIN_IMAGE_SIZE,
                                         GIMP_MAX_IMAGE_SIZE);
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (options->size_se), 1,
                                         GIMP_MIN_IMAGE_SIZE,
                                         GIMP_MAX_IMAGE_SIZE);

  gimp_size_entry_set_size (GIMP_SIZE_ENTRY (options->size_se), 0,
			    0, gimage->width);
  gimp_size_entry_set_size (GIMP_SIZE_ENTRY (options->size_se), 1,
			    0, gimage->height);

  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (options->size_se), 0,
			      gimage->width);
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (options->size_se), 1,
			      gimage->height);

  gtk_widget_show (table);

  /*  The radio frame  */
683 684 685 686 687 688 689 690
  frame = gimp_enum_radio_frame_new_with_range (GIMP_TYPE_FILL_TYPE,
                                                GIMP_FOREGROUND_FILL,
                                                GIMP_TRANSPARENT_FILL,
                                                gtk_label_new (_("Layer Fill Type")),
                                                2,
                                                G_CALLBACK (gimp_radio_button_update),
                                                &options->fill_type,
                                                &button);
691 692
  gimp_radio_group_set_active (GTK_RADIO_BUTTON (button),
                               GINT_TO_POINTER (options->fill_type));  
Michael Natterer's avatar
Michael Natterer committed
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725

  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  gtk_widget_show (vbox);
  gtk_widget_show (options->query_box);
}

/**************************************/
/*  The edit layer attributes dialog  */
/**************************************/

typedef struct _EditLayerOptions EditLayerOptions;

struct _EditLayerOptions
{
  GtkWidget *query_box;
  GtkWidget *name_entry;
  GimpLayer *layer;
  GimpImage *gimage;
};

static void
edit_layer_query_ok_callback (GtkWidget *widget,
			      gpointer   data)
{
  EditLayerOptions *options;
  GimpLayer        *layer;

  options = (EditLayerOptions *) data;

  if ((layer = options->layer))
    {
726 727 728 729 730
      const gchar *new_name;

      new_name = gtk_entry_get_text (GTK_ENTRY (options->name_entry));

      if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (layer))))
Michael Natterer's avatar
Michael Natterer committed
731
        {
732
          undo_push_group_start (options->gimage, LAYER_PROPERTIES_UNDO_GROUP);
Michael Natterer's avatar
Michael Natterer committed
733

734 735 736 737 738 739 740 741 742 743 744 745 746
          if (gimp_layer_is_floating_sel (layer))
            {
              /*  If the layer is a floating selection, make it a layer  */

              floating_sel_to_layer (layer);
            }

          undo_push_item_rename (options->gimage, GIMP_ITEM (layer));

          gimp_object_set_name (GIMP_OBJECT (layer), new_name);

          undo_push_group_end (options->gimage);
        }
Michael Natterer's avatar
Michael Natterer committed
747 748
    }

749
  gimp_image_flush (options->gimage);
Michael Natterer's avatar
Michael Natterer committed
750 751 752 753 754 755 756 757 758 759 760 761

  gtk_widget_destroy (options->query_box); 
}

void
layers_edit_layer_query (GimpLayer *layer)
{
  EditLayerOptions *options;
  GtkWidget        *vbox;
  GtkWidget        *hbox;
  GtkWidget        *label;

762 763
  options = g_new0 (EditLayerOptions, 1);

Michael Natterer's avatar
Michael Natterer committed
764
  options->layer  = layer;
765
  options->gimage = gimp_item_get_image (GIMP_ITEM (layer));
Michael Natterer's avatar
Michael Natterer committed
766 767 768 769 770 771 772 773 774

  /*  The dialog  */
  options->query_box =
    gimp_dialog_new (_("Edit Layer Attributes"), "edit_layer_attributes",
		     gimp_standard_help_func,
		     "dialogs/layers/edit_layer_attributes.html",
		     GTK_WIN_POS_MOUSE,
		     FALSE, TRUE, FALSE,

775
		     GTK_STOCK_CANCEL, gtk_widget_destroy,
Michael Natterer's avatar
Michael Natterer committed
776 777
		     NULL, 1, NULL, FALSE, TRUE,

778 779 780
		     GTK_STOCK_OK, edit_layer_query_ok_callback,
		     options, NULL, NULL, TRUE, FALSE,

Michael Natterer's avatar
Michael Natterer committed
781 782
		     NULL);

783 784 785
  g_object_weak_ref (G_OBJECT (options->query_box),
		     (GWeakNotify) g_free,
		     options);
Michael Natterer's avatar
Michael Natterer committed
786

787 788 789 790
  g_signal_connect_object (G_OBJECT (layer), "removed",
			   G_CALLBACK (gtk_widget_destroy),
			   G_OBJECT (options->query_box),
			   G_CONNECT_SWAPPED);
791

Michael Natterer's avatar
Michael Natterer committed
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
  /*  The main vbox  */
  vbox = gtk_vbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
		     vbox);

  /*  The name hbox, label and entry  */
  hbox = gtk_hbox_new (FALSE, 4);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

  label = gtk_label_new (_("Layer name:"));
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  options->name_entry = gtk_entry_new ();
  gtk_box_pack_start (GTK_BOX (hbox), options->name_entry, TRUE, TRUE, 0);
  gtk_entry_set_text (GTK_ENTRY (options->name_entry),
		      ((gimp_layer_is_floating_sel (layer) ?
			_("Floating Selection") :
			gimp_object_get_name (GIMP_OBJECT (layer)))));
  gtk_widget_show (options->name_entry);

814 815 816 817
  g_signal_connect (G_OBJECT (options->name_entry), "activate",
		    G_CALLBACK (edit_layer_query_ok_callback),
		    options);

Michael Natterer's avatar
Michael Natterer committed
818 819 820 821 822 823 824 825 826 827 828 829 830 831
  gtk_widget_show (hbox);

  gtk_widget_show (vbox);
  gtk_widget_show (options->query_box);
}

/*******************************/
/*  The add mask query dialog  */
/*******************************/

typedef struct _AddMaskOptions AddMaskOptions;

struct _AddMaskOptions
{
832 833 834
  GtkWidget       *query_box;
  GimpLayer       *layer;
  GimpAddMaskType  add_mask_type;
Michael Natterer's avatar
Michael Natterer committed
835 836 837 838 839 840 841 842 843 844 845 846 847
};

static void
add_mask_query_ok_callback (GtkWidget *widget,
			    gpointer   data)
{
  AddMaskOptions *options;
  GimpImage      *gimage;
  GimpLayerMask  *mask;
  GimpLayer      *layer;

  options = (AddMaskOptions *) data;

848
  if ((layer = (options->layer)) && (gimage = GIMP_ITEM (layer)->gimage))
Michael Natterer's avatar
Michael Natterer committed
849 850 851
    {
      mask = gimp_layer_create_mask (layer, options->add_mask_type);
      gimp_layer_add_mask (layer, mask, TRUE);
852
      gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
    }

  gtk_widget_destroy (options->query_box);
}

static void
layers_add_mask_query (GimpLayer *layer)
{
  AddMaskOptions *options;
  GtkWidget      *frame;
  GimpImage      *gimage;
  
  /*  The new options structure  */
  options = g_new (AddMaskOptions, 1);
  options->layer         = layer;
868
  options->add_mask_type = GIMP_ADD_WHITE_MASK;
Michael Natterer's avatar
Michael Natterer committed
869

870
  gimage = gimp_item_get_image (GIMP_ITEM (layer));
Michael Natterer's avatar
Michael Natterer committed
871 872 873 874 875 876 877 878 879
  
  /*  The dialog  */
  options->query_box =
    gimp_dialog_new (_("Add Mask Options"), "add_mask_options",
		     gimp_standard_help_func,
		     "dialogs/layers/add_layer_mask.html",
		     GTK_WIN_POS_MOUSE,
		     FALSE, TRUE, FALSE,

880
		     GTK_STOCK_CANCEL, gtk_widget_destroy,
Michael Natterer's avatar
Michael Natterer committed
881 882
		     NULL, 1, NULL, FALSE, TRUE,

883 884 885
		     GTK_STOCK_OK, add_mask_query_ok_callback,
		     options, NULL, NULL, TRUE, FALSE,

Michael Natterer's avatar
Michael Natterer committed
886 887
		     NULL);

888 889 890
  g_object_weak_ref (G_OBJECT (options->query_box),
		     (GWeakNotify) g_free,
		     options);
Michael Natterer's avatar
Michael Natterer committed
891

892 893 894 895
  g_signal_connect_object (G_OBJECT (layer), "removed",
			   G_CALLBACK (gtk_widget_destroy),
			   G_OBJECT (options->query_box),
			   G_CONNECT_SWAPPED);
896

Michael Natterer's avatar
Michael Natterer committed
897 898 899
  /*  The radio frame and box  */
  if (gimage->selection_mask)
    {
900
      options->add_mask_type = GIMP_ADD_SELECTION_MASK;
Michael Natterer's avatar
Michael Natterer committed
901

902 903 904 905 906 907 908
      frame =
        gimp_radio_group_new2 (TRUE, _("Initialize Layer Mask to:"),
                               G_CALLBACK (gimp_radio_button_update),
                               &options->add_mask_type,
                               GINT_TO_POINTER (options->add_mask_type),

                               _("Selection"),
909
                               GINT_TO_POINTER (GIMP_ADD_SELECTION_MASK), NULL,
910
                               _("Inverse Selection"),
911
                               GINT_TO_POINTER (GIMP_ADD_INVERSE_SELECTION_MASK), NULL,
912 913

                               _("Grayscale Copy of Layer"),
914
                               GINT_TO_POINTER (GIMP_ADD_COPY_MASK), NULL,
915
                               _("Inverse Grayscale Copy of Layer"),
916
                               GINT_TO_POINTER (GIMP_ADD_INVERSE_COPY_MASK), NULL,
917 918

                               _("White (Full Opacity)"),
919
                               GINT_TO_POINTER (GIMP_ADD_WHITE_MASK), NULL,
920
                               _("Black (Full Transparency)"),
921
                               GINT_TO_POINTER (GIMP_ADD_BLACK_MASK), NULL,
922
                               _("Layer's Alpha Channel"),
923
                               GINT_TO_POINTER (GIMP_ADD_ALPHA_MASK), NULL,
924 925

                               NULL);
Michael Natterer's avatar
Michael Natterer committed
926 927 928
    }
  else
    {
929 930 931 932 933 934 935
      frame =
        gimp_radio_group_new2 (TRUE, _("Initialize Layer Mask to:"),
                               G_CALLBACK (gimp_radio_button_update),
                               &options->add_mask_type,
                               GINT_TO_POINTER (options->add_mask_type),

                               _("Grayscale Copy of Layer"),
936
                               GINT_TO_POINTER (GIMP_ADD_COPY_MASK), NULL,
937
                               _("Inverse Grayscale Copy of Layer"),
938
                               GINT_TO_POINTER (GIMP_ADD_INVERSE_COPY_MASK), NULL,
939 940

                               _("White (Full Opacity)"),
941
                               GINT_TO_POINTER (GIMP_ADD_WHITE_MASK), NULL,
942
                               _("Black (Full Transparency)"),
943
                               GINT_TO_POINTER (GIMP_ADD_BLACK_MASK), NULL,
944
                               _("Layer's Alpha Channel"),
945
                               GINT_TO_POINTER (GIMP_ADD_ALPHA_MASK), NULL,
946 947

                               NULL);
Michael Natterer's avatar
Michael Natterer committed
948
    }
949

Michael Natterer's avatar
Michael Natterer committed
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
  gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
		     frame);
  gtk_widget_show (frame);

  gtk_widget_show (options->query_box);
}


/****************************/
/*  The scale layer dialog  */
/****************************/

typedef struct _ScaleLayerOptions ScaleLayerOptions;

struct _ScaleLayerOptions
{
  GimpLayer *layer;
  Resize    *resize;
};

static void
scale_layer_query_ok_callback (GtkWidget *widget,
			       gpointer   data)
{
  ScaleLayerOptions *options;
  GimpLayer         *layer;

  options = (ScaleLayerOptions *) data;

  if (options->resize->width > 0 && options->resize->height > 0 &&
      (layer =  (options->layer)))
    {
983 984
      GimpImage *gimage;

Michael Natterer's avatar
Michael Natterer committed
985 986
      gtk_widget_set_sensitive (options->resize->resize_shell, FALSE);

987 988 989
      gimage = gimp_item_get_image (GIMP_ITEM (layer));

      if (gimage)
Michael Natterer's avatar
Michael Natterer committed
990
	{
Michael Natterer's avatar
Michael Natterer committed
991
	  undo_push_group_start (gimage, LAYER_SCALE_UNDO_GROUP);
Michael Natterer's avatar
Michael Natterer committed
992 993 994 995 996

	  if (gimp_layer_is_floating_sel (layer))
	    floating_sel_relax (layer, TRUE);

	  gimp_layer_scale (layer, 
997 998 999
			    options->resize->width,
                            options->resize->height,
                            options->resize->interpolation,
Michael Natterer's avatar
Michael Natterer committed
1000 1001 1002 1003 1004 1005 1006
			    TRUE);

	  if (gimp_layer_is_floating_sel (layer))
	    floating_sel_rigor (layer, TRUE);

	  undo_push_group_end (gimage);

1007
          gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
	}

      gtk_widget_destroy (options->resize->resize_shell);
    }
  else
    {
      g_message (_("Invalid width or height.\n"
		   "Both must be positive."));
    }
}

static void
layers_scale_layer_query (GimpImage *gimage,
Michael Natterer's avatar
Michael Natterer committed
1021
                          GimpLayer *layer)
Michael Natterer's avatar
Michael Natterer committed
1022 1023 1024 1025 1026 1027 1028
{
  ScaleLayerOptions *options;

  /*  the new options structure  */
  options = g_new (ScaleLayerOptions, 1);
  options->layer  = layer;
  options->resize =
Michael Natterer's avatar
Michael Natterer committed
1029 1030
    resize_widget_new (gimage,
                       ScaleWidget,
Michael Natterer's avatar
Michael Natterer committed
1031
		       ResizeLayer,
1032
		       G_OBJECT (layer),
Michael Natterer's avatar
Michael Natterer committed
1033 1034 1035 1036 1037 1038 1039
		       "removed",
		       gimp_drawable_width (GIMP_DRAWABLE (layer)),
		       gimp_drawable_height (GIMP_DRAWABLE (layer)),
		       gimage->xresolution,
		       gimage->yresolution,
		       gimage->unit,
		       TRUE,
1040
		       G_CALLBACK (scale_layer_query_ok_callback),
Michael Natterer's avatar
Michael Natterer committed
1041 1042 1043
		       NULL,
		       options);

1044 1045 1046
  g_object_weak_ref (G_OBJECT (options->resize->resize_shell),
		     (GWeakNotify) g_free,
		     options);
Michael Natterer's avatar
Michael Natterer committed
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074

  gtk_widget_show (options->resize->resize_shell);
}

/*****************************/
/*  The resize layer dialog  */
/*****************************/

typedef struct _ResizeLayerOptions ResizeLayerOptions;

struct _ResizeLayerOptions
{
  GimpLayer *layer;
  Resize    *resize;
};

static void
resize_layer_query_ok_callback (GtkWidget *widget,
				gpointer   data)
{
  ResizeLayerOptions *options;
  GimpLayer          *layer;

  options = (ResizeLayerOptions *) data;

  if (options->resize->width > 0 && options->resize->height > 0 &&
      (layer = (options->layer)))
    {
1075 1076
      GimpImage *gimage;

Michael Natterer's avatar
Michael Natterer committed
1077 1078
      gtk_widget_set_sensitive (options->resize->resize_shell, FALSE);

1079 1080 1081
      gimage = gimp_item_get_image (GIMP_ITEM (layer));

      if (gimage)
Michael Natterer's avatar
Michael Natterer committed
1082
	{
Michael Natterer's avatar
Michael Natterer committed
1083
	  undo_push_group_start (gimage, LAYER_RESIZE_UNDO_GROUP);
Michael Natterer's avatar
Michael Natterer committed
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098

	  if (gimp_layer_is_floating_sel (layer))
	    floating_sel_relax (layer, TRUE);

	  gimp_layer_resize (layer,
			     options->resize->width,
			     options->resize->height,
			     options->resize->offset_x,
			     options->resize->offset_y);

	  if (gimp_layer_is_floating_sel (layer))
	    floating_sel_rigor (layer, TRUE);

	  undo_push_group_end (gimage);

1099
          gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
	}

      gtk_widget_destroy (options->resize->resize_shell);
    }
  else
    {
      g_message (_("Invalid width or height.\n"
		   "Both must be positive."));
    }
}

static void
layers_resize_layer_query (GimpImage *gimage,
Michael Natterer's avatar
Michael Natterer committed
1113
                           GimpLayer *layer)
Michael Natterer's avatar
Michael Natterer committed
1114 1115 1116 1117 1118 1119 1120
{
  ResizeLayerOptions *options;

  /*  the new options structure  */
  options = g_new (ResizeLayerOptions, 1);
  options->layer  = layer;
  options->resize =
Michael Natterer's avatar
Michael Natterer committed
1121 1122
    resize_widget_new (gimage,
                       ResizeWidget,
Michael Natterer's avatar
Michael Natterer committed
1123
		       ResizeLayer,
1124
		       G_OBJECT (layer),
Michael Natterer's avatar
Michael Natterer committed
1125 1126 1127 1128 1129 1130 1131
		       "removed",
		       gimp_drawable_width (GIMP_DRAWABLE (layer)),
		       gimp_drawable_height (GIMP_DRAWABLE (layer)),
		       gimage->xresolution,
		       gimage->yresolution,
		       gimage->unit,
		       TRUE,
1132
		       G_CALLBACK (resize_layer_query_ok_callback),
Michael Natterer's avatar
Michael Natterer committed
1133 1134 1135
		       NULL,
		       options);

1136 1137 1138
  g_object_weak_ref (G_OBJECT (options->resize->resize_shell),
		     (GWeakNotify) g_free,
		     options);
Michael Natterer's avatar
Michael Natterer committed
1139 1140 1141 1142

  gtk_widget_show (options->resize->resize_shell);
}

1143
void
1144 1145
layers_menu_update (GtkItemFactory *factory,
                    gpointer        data)
1146
{
1147
  GimpImage *gimage;
1148
  GimpLayer *layer;
1149 1150
  gboolean   fs         = FALSE;    /*  floating sel           */
  gboolean   ac         = FALSE;    /*  active channel         */
1151 1152 1153 1154 1155 1156 1157 1158 1159
  gboolean   lm         = FALSE;    /*  layer mask             */
  gboolean   lp         = FALSE;    /*  layers present         */
  gboolean   alpha      = FALSE;    /*  alpha channel present  */
  gboolean   indexed    = FALSE;    /*  is indexed             */
  gboolean   next_alpha = FALSE;
  GList     *list;
  GList     *next       = NULL;
  GList     *prev       = NULL;

1160
  gimage = GIMP_IMAGE (data);
1161 1162 1163 1164 1165 1166

  layer = gimp_image_get_active_layer (gimage);

  if (layer)
    lm = (gimp_layer_get_mask (layer)) ? TRUE : FALSE;

1167 1168
  fs = (gimp_image_floating_sel (gimage) != NULL);
  ac = (gimp_image_get_active_channel (gimage) != NULL);
1169

1170
  alpha = layer && gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
1171 1172

  lp      = ! gimp_image_is_empty (gimage);
1173
  indexed = (gimp_image_base_type (gimage) == GIMP_INDEXED);
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187

  for (list = GIMP_LIST (gimage->layers)->list;
       list;
       list = g_list_next (list)) 
    {
      if (layer == (GimpLayer *) list->data)
	{
	  prev = g_list_previous (list);
	  next = g_list_next (list);
	  break;
	}
    }

  if (next)
1188
    next_alpha