~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/core/gimpselection.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
30
30
#include "base/tile.h"
31
31
#include "base/tile-manager.h"
32
32
 
 
33
#include "gimp.h"
33
34
#include "gimpcontext.h"
34
35
#include "gimpimage.h"
35
36
#include "gimpimage-undo.h"
42
43
#include "gimp-intl.h"
43
44
 
44
45
 
45
 
static void       gimp_selection_class_init    (GimpSelectionClass *klass);
46
 
static void       gimp_selection_init          (GimpSelection      *selection);
47
 
 
48
46
static gboolean   gimp_selection_is_attached   (GimpItem        *item);
49
47
static void       gimp_selection_translate     (GimpItem        *item,
50
48
                                                gint             offset_x,
76
74
                                                gboolean         clip_result);
77
75
static gboolean   gimp_selection_stroke        (GimpItem        *item,
78
76
                                                GimpDrawable    *drawable,
79
 
                                                GimpContext     *context,
80
77
                                                GimpStrokeDesc  *stroke_desc);
81
78
 
82
79
static void gimp_selection_invalidate_boundary (GimpDrawable    *drawable);
96
93
                                                gint            *x2,
97
94
                                                gint            *y2);
98
95
static gboolean   gimp_selection_is_empty      (GimpChannel     *channel);
99
 
static gint       gimp_selection_value         (GimpChannel     *channel,
100
 
                                                gint             x,
101
 
                                                gint             y);
102
96
static void       gimp_selection_feather       (GimpChannel     *channel,
103
97
                                                gdouble          radius_x,
104
98
                                                gdouble          radius_y,
115
109
static void       gimp_selection_border        (GimpChannel     *channel,
116
110
                                                gint             radius_x,
117
111
                                                gint             radius_y,
 
112
                                                gboolean         feather,
 
113
                                                gboolean         edge_lock,
118
114
                                                gboolean         push_undo);
119
115
static void       gimp_selection_grow          (GimpChannel     *channel,
120
116
                                                gint             radius_x,
130
126
                                                Tile            *tile);
131
127
 
132
128
 
133
 
static GimpChannelClass *parent_class = NULL;
134
 
 
135
 
 
136
 
GType
137
 
gimp_selection_get_type (void)
138
 
{
139
 
  static GType selection_type = 0;
140
 
 
141
 
  if (! selection_type)
142
 
    {
143
 
      static const GTypeInfo selection_info =
144
 
      {
145
 
        sizeof (GimpSelectionClass),
146
 
        (GBaseInitFunc) NULL,
147
 
        (GBaseFinalizeFunc) NULL,
148
 
        (GClassInitFunc) gimp_selection_class_init,
149
 
        NULL,           /* class_finalize */
150
 
        NULL,           /* class_data     */
151
 
        sizeof (GimpSelection),
152
 
        0,              /* n_preallocs    */
153
 
        (GInstanceInitFunc) gimp_selection_init,
154
 
      };
155
 
 
156
 
      selection_type = g_type_register_static (GIMP_TYPE_CHANNEL,
157
 
                                               "GimpSelection",
158
 
                                               &selection_info, 0);
159
 
    }
160
 
 
161
 
  return selection_type;
162
 
}
 
129
G_DEFINE_TYPE (GimpSelection, gimp_selection, GIMP_TYPE_CHANNEL)
 
130
 
 
131
#define parent_class gimp_selection_parent_class
 
132
 
163
133
 
164
134
static void
165
135
gimp_selection_class_init (GimpSelectionClass *klass)
169
139
  GimpDrawableClass *drawable_class = GIMP_DRAWABLE_CLASS (klass);
170
140
  GimpChannelClass  *channel_class  = GIMP_CHANNEL_CLASS (klass);
171
141
 
172
 
  parent_class = g_type_class_peek_parent (klass);
173
 
 
174
142
  viewable_class->default_stock_id    = "gimp-selection";
175
143
 
176
144
  item_class->is_attached             = gimp_selection_is_attached;
188
156
  channel_class->boundary             = gimp_selection_boundary;
189
157
  channel_class->bounds               = gimp_selection_bounds;
190
158
  channel_class->is_empty             = gimp_selection_is_empty;
191
 
  channel_class->value                = gimp_selection_value;
192
159
  channel_class->feather              = gimp_selection_feather;
193
160
  channel_class->sharpen              = gimp_selection_sharpen;
194
161
  channel_class->clear                = gimp_selection_clear;
217
184
static gboolean
218
185
gimp_selection_is_attached (GimpItem *item)
219
186
{
220
 
  return (GIMP_IS_IMAGE (item->gimage) &&
221
 
          gimp_image_get_mask (item->gimage) == GIMP_CHANNEL (item));
 
187
  return (GIMP_IS_IMAGE (item->image) &&
 
188
          gimp_image_get_mask (item->image) == GIMP_CHANNEL (item));
222
189
}
223
190
 
224
191
static void
289
256
static gboolean
290
257
gimp_selection_stroke (GimpItem       *item,
291
258
                       GimpDrawable   *drawable,
292
 
                       GimpContext    *context,
293
259
                       GimpStrokeDesc *stroke_desc)
294
260
{
295
261
  GimpSelection  *selection = GIMP_SELECTION (item);
304
270
                               &num_dummy_in, &num_dummy_out,
305
271
                               0, 0, 0, 0))
306
272
    {
307
 
      g_message (_("No selection to stroke."));
 
273
      gimp_message (gimp_item_get_image (item)->gimp, NULL,
 
274
                    GIMP_MESSAGE_WARNING,
 
275
                    _("There is no selection to stroke."));
308
276
      return FALSE;
309
277
    }
310
278
 
311
279
  selection->stroking = TRUE;
312
280
 
313
 
  retval = GIMP_ITEM_CLASS (parent_class)->stroke (item, drawable, context,
314
 
                                                   stroke_desc);
 
281
  retval = GIMP_ITEM_CLASS (parent_class)->stroke (item, drawable, stroke_desc);
315
282
 
316
283
  selection->stroking = FALSE;
317
284
 
321
288
static void
322
289
gimp_selection_invalidate_boundary (GimpDrawable *drawable)
323
290
{
324
 
  GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
 
291
  GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
325
292
  GimpLayer *layer;
326
293
 
327
294
  /*  Turn the current selection off  */
328
 
  gimp_image_selection_control (gimage, GIMP_SELECTION_OFF);
 
295
  gimp_image_selection_control (image, GIMP_SELECTION_OFF);
329
296
 
330
297
  GIMP_DRAWABLE_CLASS (parent_class)->invalidate_boundary (drawable);
331
298
 
333
300
   *  we need to do this since this selection mask can act as an additional
334
301
   *  mask in the composition of the floating selection
335
302
   */
336
 
  layer = gimp_image_get_active_layer (gimage);
 
303
  layer = gimp_image_get_active_layer (image);
337
304
 
338
305
  if (layer && gimp_layer_is_floating_sel (layer))
339
306
    gimp_drawable_update (GIMP_DRAWABLE (layer),
340
 
                          0, 0,
341
 
                          GIMP_ITEM (layer)->width,
342
 
                          GIMP_ITEM (layer)->height);
 
307
                          0, 0,
 
308
                          GIMP_ITEM (layer)->width,
 
309
                          GIMP_ITEM (layer)->height);
343
310
 
344
311
  /*  invalidate the preview  */
345
312
  drawable->preview_valid = FALSE;
356
323
                         gint             unused3,
357
324
                         gint             unused4)
358
325
{
359
 
  GimpImage    *gimage = gimp_item_get_image (GIMP_ITEM (channel));
 
326
  GimpImage    *image = gimp_item_get_image (GIMP_ITEM (channel));
360
327
  GimpDrawable *drawable;
361
328
  GimpLayer    *layer;
362
329
 
363
 
  if ((layer = gimp_image_floating_sel (gimage)))
 
330
  if ((layer = gimp_image_floating_sel (image)))
364
331
    {
365
332
      /*  If there is a floating selection, then
366
333
       *  we need to do some slightly different boundaries.
382
349
 
383
350
      return TRUE;
384
351
    }
385
 
  else if ((drawable = gimp_image_active_drawable (gimage)) &&
386
 
           GIMP_IS_CHANNEL (drawable))
 
352
  else if ((drawable = gimp_image_active_drawable (image)) &&
 
353
           GIMP_IS_CHANNEL (drawable))
387
354
    {
388
355
      /*  Otherwise, return the boundary...if a channel is active  */
389
356
 
392
359
                                                          num_segs_in,
393
360
                                                          num_segs_out,
394
361
                                                          0, 0,
395
 
                                                          gimage->width,
396
 
                                                          gimage->height);
 
362
                                                          image->width,
 
363
                                                          image->height);
397
364
    }
398
 
  else if ((layer = gimp_image_get_active_layer (gimage)))
 
365
  else if ((layer = gimp_image_get_active_layer (image)))
399
366
    {
400
367
      /*  If a layer is active, we return multiple boundaries based
401
368
       *  on the extents
407
374
 
408
375
      gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);
409
376
 
410
 
      x1 = CLAMP (off_x, 0, gimage->width);
411
 
      y1 = CLAMP (off_y, 0, gimage->height);
 
377
      x1 = CLAMP (off_x, 0, image->width);
 
378
      y1 = CLAMP (off_y, 0, image->height);
412
379
      x2 = CLAMP (off_x + gimp_item_width (GIMP_ITEM (layer)), 0,
413
 
                  gimage->width);
 
380
                  image->width);
414
381
      y2 = CLAMP (off_y + gimp_item_height (GIMP_ITEM (layer)), 0,
415
 
                  gimage->height);
 
382
                  image->height);
416
383
 
417
384
      return GIMP_CHANNEL_CLASS (parent_class)->boundary (channel,
418
385
                                                          segs_in, segs_out,
454
421
  return GIMP_CHANNEL_CLASS (parent_class)->is_empty (channel);
455
422
}
456
423
 
457
 
static gint
458
 
gimp_selection_value (GimpChannel *channel,
459
 
                      gint         x,
460
 
                      gint         y)
461
 
{
462
 
  return GIMP_CHANNEL_CLASS (parent_class)->value (channel, x, y);
463
 
}
464
 
 
465
424
static void
466
425
gimp_selection_feather (GimpChannel *channel,
467
426
                        gdouble      radius_x,
505
464
gimp_selection_border (GimpChannel *channel,
506
465
                       gint         radius_x,
507
466
                       gint         radius_y,
 
467
                       gboolean     feather,
 
468
                       gboolean     edge_lock,
508
469
                       gboolean     push_undo)
509
470
{
510
 
  GIMP_CHANNEL_CLASS (parent_class)->border (channel, radius_x, radius_y,
 
471
  GIMP_CHANNEL_CLASS (parent_class)->border (channel,
 
472
                                             radius_x, radius_y,
 
473
                                             feather, edge_lock,
511
474
                                             push_undo);
512
475
}
513
476
 
517
480
                     gint         radius_y,
518
481
                     gboolean     push_undo)
519
482
{
520
 
  GIMP_CHANNEL_CLASS (parent_class)->grow (channel, radius_x, radius_y,
 
483
  GIMP_CHANNEL_CLASS (parent_class)->grow (channel,
 
484
                                           radius_x, radius_y,
521
485
                                           push_undo);
522
486
}
523
487
 
528
492
                       gboolean     edge_lock,
529
493
                       gboolean     push_undo)
530
494
{
531
 
  GIMP_CHANNEL_CLASS (parent_class)->shrink (channel, radius_x, radius_y,
532
 
                                             edge_lock, push_undo);
 
495
  GIMP_CHANNEL_CLASS (parent_class)->shrink (channel,
 
496
                                             radius_x, radius_y, edge_lock,
 
497
                                             push_undo);
533
498
}
534
499
 
535
500
static void
538
503
{
539
504
  /*  Set the contents of the tile to empty  */
540
505
  memset (tile_data_pointer (tile, 0, 0),
541
 
          TRANSPARENT_OPACITY, tile_size (tile));
 
506
          TRANSPARENT_OPACITY, tile_size (tile));
542
507
}
543
508
 
544
509
 
545
510
/*  public functions  */
546
511
 
547
512
GimpChannel *
548
 
gimp_selection_new (GimpImage *gimage,
 
513
gimp_selection_new (GimpImage *image,
549
514
                    gint       width,
550
515
                    gint       height)
551
516
{
552
517
  GimpRGB      black = { 0.0, 0.0, 0.0, 0.5 };
553
518
  GimpChannel *channel;
554
519
 
555
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
 
520
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
556
521
 
557
522
  channel = g_object_new (GIMP_TYPE_SELECTION, NULL);
558
523
 
559
524
  gimp_drawable_configure (GIMP_DRAWABLE (channel),
560
 
                           gimage,
 
525
                           image,
561
526
                           0, 0, width, height,
562
527
                           GIMP_GRAY_IMAGE,
563
528
                           _("Selection Mask"));
569
534
 
570
535
  /*  Set the validate procedure  */
571
536
  tile_manager_set_validate_proc (GIMP_DRAWABLE (channel)->tiles,
572
 
                                  gimp_selection_validate);
 
537
                                  gimp_selection_validate);
573
538
 
574
539
  return channel;
575
540
}
596
561
 
597
562
  /*  copy the channel to the mask  */
598
563
  pixel_region_init (&srcPR, GIMP_DRAWABLE (channel)->tiles,
599
 
                     0, 0, src_item->width, src_item->height,
 
564
                     0, 0, src_item->width, src_item->height,
600
565
                     FALSE);
601
566
  pixel_region_init (&destPR, GIMP_DRAWABLE (selection)->tiles,
602
 
                     0, 0, dest_item->width, dest_item->height,
 
567
                     0, 0, dest_item->width, dest_item->height,
603
568
                     TRUE);
604
569
  copy_region (&srcPR, &destPR);
605
570
 
612
577
GimpChannel *
613
578
gimp_selection_save (GimpChannel *selection)
614
579
{
615
 
  GimpImage   *gimage;
 
580
  GimpImage   *image;
616
581
  GimpChannel *new_channel;
617
582
 
618
583
  g_return_val_if_fail (GIMP_IS_SELECTION (selection), NULL);
619
584
 
620
 
  gimage = gimp_item_get_image (GIMP_ITEM (selection));
 
585
  image = gimp_item_get_image (GIMP_ITEM (selection));
621
586
 
622
587
  new_channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
623
588
                                                   GIMP_TYPE_CHANNEL,
626
591
  /*  saved selections are not visible by default  */
627
592
  gimp_item_set_visible (GIMP_ITEM (new_channel), FALSE, FALSE);
628
593
 
629
 
  gimp_image_add_channel (gimage, new_channel, -1);
 
594
  gimp_image_add_channel (image, new_channel, -1);
630
595
 
631
596
  return new_channel;
632
597
}
639
604
                        gboolean      keep_indexed,
640
605
                        gboolean      add_alpha)
641
606
{
642
 
  GimpImage         *gimage;
 
607
  GimpImage         *image;
643
608
  TileManager       *tiles;
644
609
  PixelRegion        srcPR, destPR, maskPR;
645
610
  guchar             bg_color[MAX_CHANNELS];
654
619
  g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
655
620
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
656
621
 
657
 
  gimage = gimp_item_get_image (GIMP_ITEM (selection));
 
622
  image = gimp_item_get_image (GIMP_ITEM (selection));
658
623
 
659
624
  /*  If there are no bounds, then just extract the entire image
660
625
   *  This may not be the correct behavior, but after getting rid
665
630
  non_empty = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
666
631
  if (non_empty && ((x1 == x2) || (y1 == y2)))
667
632
    {
668
 
      g_message (_("Unable to cut or copy because the "
669
 
                   "selected region is empty."));
 
633
      gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING,
 
634
                    _("Unable to cut or copy because the "
 
635
                      "selected region is empty."));
670
636
      return NULL;
671
637
    }
672
638
 
 
639
  /*  If there is a selection, we must add alpha because the selection
 
640
   *  could have any shape.
 
641
   */
 
642
  if (non_empty)
 
643
    add_alpha = TRUE;
 
644
 
673
645
  /*  How many bytes in the temp buffer?  */
674
646
  switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)))
675
647
    {
685
657
 
686
658
    case GIMP_INDEXED:
687
659
      if (keep_indexed)
688
 
        {
689
 
          bytes = add_alpha ? 2 : drawable->bytes;
690
 
          base_type = GIMP_GRAY;
691
 
        }
 
660
        {
 
661
          bytes = add_alpha ? 2 : drawable->bytes;
 
662
          base_type = GIMP_GRAY;
 
663
        }
692
664
      else
693
 
        {
694
 
          bytes = add_alpha ? 4 : drawable->bytes;
695
 
          base_type = GIMP_INDEXED;
696
 
        }
 
665
        {
 
666
          bytes = (add_alpha ||
 
667
                   gimp_drawable_has_alpha (drawable)) ? 4 : 3;
 
668
          base_type = GIMP_INDEXED;
 
669
        }
697
670
      break;
698
671
 
699
672
    default:
701
674
      break;
702
675
    }
703
676
 
704
 
  gimp_image_get_background (gimage, drawable, context, bg_color);
 
677
  gimp_image_get_background (image, context, gimp_drawable_type (drawable),
 
678
                             bg_color);
705
679
 
706
680
  /*  If a cut was specified, and the selection mask is not empty,
707
681
   *  push an undo
716
690
  tile_manager_set_offsets (tiles, x1 + off_x, y1 + off_y);
717
691
 
718
692
  /* configure the pixel regions  */
719
 
  pixel_region_init (&srcPR, gimp_drawable_data (drawable),
720
 
                     x1, y1,
 
693
  pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
 
694
                     x1, y1,
721
695
                     x2 - x1, y2 - y1,
722
696
                     cut_image);
723
697
  pixel_region_init (&destPR, tiles,
727
701
 
728
702
  if (non_empty) /*  If there is a selection, extract from it  */
729
703
    {
730
 
      pixel_region_init (&maskPR, gimp_drawable_data (GIMP_DRAWABLE (selection)),
731
 
                         (x1 + off_x), (y1 + off_y), (x2 - x1), (y2 - y1),
732
 
                         FALSE);
 
704
      pixel_region_init (&maskPR,
 
705
                         gimp_drawable_get_tiles (GIMP_DRAWABLE (selection)),
 
706
                         (x1 + off_x), (y1 + off_y), (x2 - x1), (y2 - y1),
 
707
                         FALSE);
733
708
 
734
709
      extract_from_region (&srcPR, &destPR, &maskPR,
735
 
                           gimp_drawable_cmap (drawable),
736
 
                           bg_color, base_type,
737
 
                           gimp_drawable_has_alpha (drawable), cut_image);
 
710
                           gimp_drawable_get_colormap (drawable),
 
711
                           bg_color, base_type, cut_image);
738
712
 
739
713
      if (cut_image)
740
 
        {
741
 
          /*  Clear the region  */
742
 
          gimp_channel_clear (selection, NULL, TRUE);
 
714
        {
 
715
          /*  Clear the region  */
 
716
          gimp_channel_clear (selection, NULL, TRUE);
743
717
 
744
 
          /*  Update the region  */
745
 
          gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
746
 
        }
 
718
          /*  Update the region  */
 
719
          gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
 
720
        }
747
721
    }
748
722
  else /*  Otherwise, get the entire active layer  */
749
723
    {
750
724
      /*  If the layer is indexed...we need to extract pixels  */
751
725
      if (base_type == GIMP_INDEXED && !keep_indexed)
752
 
        extract_from_region (&srcPR, &destPR, NULL,
753
 
                             gimp_drawable_cmap (drawable),
754
 
                             bg_color, base_type,
755
 
                             gimp_drawable_has_alpha (drawable), FALSE);
 
726
        extract_from_region (&srcPR, &destPR, NULL,
 
727
                             gimp_drawable_get_colormap (drawable),
 
728
                             bg_color, base_type, FALSE);
756
729
      /*  If the layer doesn't have an alpha channel, add one  */
757
730
      else if (bytes > srcPR.bytes)
758
 
        add_alpha_region (&srcPR, &destPR);
 
731
        add_alpha_region (&srcPR, &destPR);
759
732
      /*  Otherwise, do a straight copy  */
760
733
      else
761
 
        copy_region (&srcPR, &destPR);
 
734
        copy_region (&srcPR, &destPR);
762
735
 
763
736
      /*  If we're cutting, remove either the layer (or floating selection),
764
737
       *  the layer mask, or the channel
765
738
       */
766
739
      if (cut_image)
767
 
        {
768
 
          if (GIMP_IS_LAYER (drawable))
769
 
            {
770
 
              if (gimp_layer_is_floating_sel (GIMP_LAYER (drawable)))
771
 
                floating_sel_remove (GIMP_LAYER (drawable));
772
 
              else
773
 
                gimp_image_remove_layer (gimage, GIMP_LAYER (drawable));
774
 
            }
775
 
          else if (GIMP_IS_LAYER_MASK (drawable))
776
 
            {
777
 
              gimp_layer_apply_mask (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)),
778
 
                                     GIMP_MASK_DISCARD, TRUE);
779
 
            }
780
 
          else if (GIMP_IS_CHANNEL (drawable))
781
 
            {
782
 
              gimp_image_remove_channel (gimage, GIMP_CHANNEL (drawable));
783
 
            }
784
 
        }
 
740
        {
 
741
          if (GIMP_IS_LAYER (drawable))
 
742
            {
 
743
              if (gimp_layer_is_floating_sel (GIMP_LAYER (drawable)))
 
744
                floating_sel_remove (GIMP_LAYER (drawable));
 
745
              else
 
746
                gimp_image_remove_layer (image, GIMP_LAYER (drawable));
 
747
            }
 
748
          else if (GIMP_IS_LAYER_MASK (drawable))
 
749
            {
 
750
              gimp_layer_apply_mask (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)),
 
751
                                     GIMP_MASK_DISCARD, TRUE);
 
752
            }
 
753
          else if (GIMP_IS_CHANNEL (drawable))
 
754
            {
 
755
              gimp_image_remove_channel (image, GIMP_CHANNEL (drawable));
 
756
            }
 
757
        }
785
758
    }
786
759
 
787
760
  return tiles;
795
768
                      gint          off_x,
796
769
                      gint          off_y)
797
770
{
798
 
  GimpImage   *gimage;
 
771
  GimpImage   *image;
799
772
  GimpLayer   *layer;
800
773
  TileManager *tiles;
801
774
  gint         x1, y1, x2, y2;
806
779
  g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
807
780
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
808
781
 
809
 
  gimage = gimp_item_get_image (GIMP_ITEM (selection));
 
782
  image = gimp_item_get_image (GIMP_ITEM (selection));
810
783
 
811
784
  /*  Make sure there is a region to float...  */
812
785
  non_empty = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
813
786
  if (! non_empty || (x1 == x2) || (y1 == y2))
814
787
    {
815
 
      g_message (_("Cannot float selection because the "
816
 
                   "selected region is empty."));
 
788
      gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING,
 
789
                    _("Cannot float selection because the "
 
790
                      "selected region is empty."));
817
791
      return NULL;
818
792
    }
819
793
 
820
794
  /*  Start an undo group  */
821
 
  gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_FS_FLOAT,
 
795
  gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_FS_FLOAT,
822
796
                               _("Float Selection"));
823
797
 
824
798
  /*  Cut or copy the selected region  */
834
808
   *  a channel or layer mask
835
809
   */
836
810
  layer = gimp_layer_new_from_tiles (tiles,
837
 
                                     gimage,
 
811
                                     image,
838
812
                                     gimp_drawable_type_with_alpha (drawable),
839
 
                                     _("Floated Layer"),
840
 
                                     GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 
813
                                     _("Floated Layer"),
 
814
                                     GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
841
815
 
842
816
  /*  Set the offsets  */
843
817
  tile_manager_get_offsets (tiles, &x1, &y1);
847
821
  /*  Free the temp buffer  */
848
822
  tile_manager_unref (tiles);
849
823
 
850
 
  /*  Add the floating layer to the gimage  */
 
824
  /*  Add the floating layer to the image  */
851
825
  floating_sel_attach (layer, drawable);
852
826
 
853
827
  /*  End an undo group  */
854
 
  gimp_image_undo_group_end (gimage);
 
828
  gimp_image_undo_group_end (image);
855
829
 
856
 
  /*  invalidate the gimage's boundary variables  */
 
830
  /*  invalidate the image's boundary variables  */
857
831
  selection->boundary_known = FALSE;
858
832
 
859
833
  return layer;