gimppatternselectbutton.c 23.7 KB
Newer Older
1 2 3 4 5 6
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 *
 * gimppatternselectbutton.c
 * Copyright (C) 1998 Andy Thomas
 *
7
 * This library is free software: you can redistribute it and/or
8 9
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
10
 * version 3 of the License, or (at your option) any later version.
11 12 13 14 15 16 17
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library.  If not, see
19
 * <https://www.gnu.org/licenses/>.
20 21 22 23
 */

#include "config.h"

24
#include <gegl.h>
25 26 27 28 29 30 31 32 33 34 35 36 37
#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

#include "gimp.h"

#include "gimpuitypes.h"
#include "gimppatternselectbutton.h"
#include "gimpuimarshal.h"

#include "libgimp-intl.h"


38 39 40 41 42 43 44 45 46
/**
 * SECTION: gimppatternselectbutton
 * @title: GimpPatternSelectButton
 * @short_description: A button which pops up a pattern select dialog.
 *
 * A button which pops up a pattern select dialog.
 **/


47 48 49
#define CELL_SIZE 20


50
#define GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE(obj) ((GimpPatternSelectButtonPrivate *) gimp_pattern_select_button_get_instance_private ((GimpPatternSelectButton *) (obj)))
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

typedef struct _GimpPatternSelectButtonPrivate GimpPatternSelectButtonPrivate;

struct _GimpPatternSelectButtonPrivate
{
  gchar     *title;

  gchar     *pattern_name;      /* Local copy */
  gint       width;
  gint       height;
  gint       bytes;
  guchar    *mask_data;         /* local copy */

  GtkWidget *inside;
  GtkWidget *preview;
  GtkWidget *popup;
};

enum
{
  PATTERN_SET,
  LAST_SIGNAL
};

enum
{
  PROP_0,
  PROP_TITLE,
  PROP_PATTERN_NAME
};


/*  local function prototypes  */

static void   gimp_pattern_select_button_finalize     (GObject      *object);

static void   gimp_pattern_select_button_set_property (GObject      *object,
                                                       guint         property_id,
                                                       const GValue *value,
                                                       GParamSpec   *pspec);
static void   gimp_pattern_select_button_get_property (GObject      *object,
                                                       guint         property_id,
                                                       GValue       *value,
                                                       GParamSpec   *pspec);

96
static void   gimp_pattern_select_button_clicked  (GimpPatternSelectButton *button);
97 98 99 100 101 102 103 104 105

static void   gimp_pattern_select_button_callback (const gchar  *pattern_name,
                                                   gint          width,
                                                   gint          height,
                                                   gint          bytes,
                                                   const guchar *mask_data,
                                                   gboolean      dialog_closing,
                                                   gpointer      user_data);

106
static void     gimp_pattern_select_preview_resize  (GimpPatternSelectButton *button);
107 108
static gboolean gimp_pattern_select_preview_events  (GtkWidget               *widget,
                                                     GdkEvent                *event,
109
                                                     GimpPatternSelectButton *button);
110 111 112 113 114 115
static void     gimp_pattern_select_preview_update  (GtkWidget               *preview,
                                                     gint                     width,
                                                     gint                     height,
                                                     gint                     bytes,
                                                     const guchar            *mask_data);

116
static void     gimp_pattern_select_button_open_popup  (GimpPatternSelectButton *button,
117 118
                                                        gint                     x,
                                                        gint                     y);
119
static void     gimp_pattern_select_button_close_popup (GimpPatternSelectButton *button);
120

121
static void   gimp_pattern_select_drag_data_received (GimpPatternSelectButton *button,
122 123 124 125 126 127 128
                                                      GdkDragContext          *context,
                                                      gint                     x,
                                                      gint                     y,
                                                      GtkSelectionData        *selection,
                                                      guint                    info,
                                                      guint                    time);

129
static GtkWidget * gimp_pattern_select_button_create_inside (GimpPatternSelectButton *button);
130 131 132 133 134 135 136


static const GtkTargetEntry target = { "application/x-gimp-pattern-name", 0 };

static guint pattern_button_signals[LAST_SIGNAL] = { 0 };


137 138
G_DEFINE_TYPE_WITH_PRIVATE (GimpPatternSelectButton, gimp_pattern_select_button,
                            GIMP_TYPE_SELECT_BUTTON)
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

static void
gimp_pattern_select_button_class_init (GimpPatternSelectButtonClass *klass)
{
  GObjectClass          *object_class        = G_OBJECT_CLASS (klass);
  GimpSelectButtonClass *select_button_class = GIMP_SELECT_BUTTON_CLASS (klass);

  object_class->finalize     = gimp_pattern_select_button_finalize;
  object_class->set_property = gimp_pattern_select_button_set_property;
  object_class->get_property = gimp_pattern_select_button_get_property;

  select_button_class->select_destroy = gimp_pattern_select_destroy;

  klass->pattern_set = NULL;

  /**
   * GimpPatternSelectButton:title:
   *
   * The title to be used for the pattern selection popup dialog.
   *
159
   * Since: 2.4
160 161 162 163 164 165 166 167 168 169 170 171 172 173
   */
  g_object_class_install_property (object_class, PROP_TITLE,
                                   g_param_spec_string ("title",
                                                        "Title",
                                                        "The title to be used for the pattern selection popup dialog",
                                                        _("Pattern Selection"),
                                                        GIMP_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY));

  /**
   * GimpPatternSelectButton:pattern-name:
   *
   * The name of the currently selected pattern.
   *
174
   * Since: 2.4
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
   */
  g_object_class_install_property (object_class, PROP_PATTERN_NAME,
                                   g_param_spec_string ("pattern-name",
                                                        "Pattern name",
                                                        "The name of the currently selected pattern",
                                                        NULL,
                                                        GIMP_PARAM_READWRITE));

  /**
   * GimpPatternSelectButton::pattern-set:
   * @widget: the object which received the signal.
   * @pattern_name: the name of the currently selected pattern.
   * @width: width of the pattern
   * @height: height of the pattern
   * @bpp: bpp of the pattern
   * @mask_data: pattern mask data
   * @dialog_closing: whether the dialog was closed or not.
   *
   * The ::pattern-set signal is emitted when the user selects a pattern.
   *
195
   * Since: 2.4
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
   */
  pattern_button_signals[PATTERN_SET] =
    g_signal_new ("pattern-set",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpPatternSelectButtonClass, pattern_set),
                  NULL, NULL,
                  _gimpui_marshal_VOID__STRING_INT_INT_INT_POINTER_BOOLEAN,
                  G_TYPE_NONE, 6,
                  G_TYPE_STRING,
                  G_TYPE_INT,
                  G_TYPE_INT,
                  G_TYPE_INT,
                  G_TYPE_POINTER,
                  G_TYPE_BOOLEAN);
}

static void
214
gimp_pattern_select_button_init (GimpPatternSelectButton *button)
215 216 217
{
  GimpPatternSelectButtonPrivate *priv;
  gint                            mask_data_size;
218 219

  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
220 221 222 223 224 225 226 227 228

  priv->pattern_name = gimp_context_get_pattern ();
  gimp_pattern_get_pixels (priv->pattern_name,
                           &priv->width,
                           &priv->height,
                           &priv->bytes,
                           &mask_data_size,
                           &priv->mask_data);

229 230
  priv->inside = gimp_pattern_select_button_create_inside (button);
  gtk_container_add (GTK_CONTAINER (button), priv->inside);
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245

  priv->popup = NULL;
}

/**
 * gimp_pattern_select_button_new:
 * @title:        Title of the dialog to use or %NULL to use the default title.
 * @pattern_name: Initial pattern name or %NULL to use current selection.
 *
 * Creates a new #GtkWidget that completely controls the selection of
 * a pattern.  This widget is suitable for placement in a table in a
 * plug-in dialog.
 *
 * Returns: A #GtkWidget that you can use in your UI.
 *
246
 * Since: 2.4
247 248 249 250 251
 */
GtkWidget *
gimp_pattern_select_button_new (const gchar *title,
                                const gchar *pattern_name)
{
252
  GtkWidget *button;
253 254

  if (title)
255 256 257 258
    button = g_object_new (GIMP_TYPE_PATTERN_SELECT_BUTTON,
                           "title",        title,
                           "pattern-name", pattern_name,
                           NULL);
259
  else
260 261 262
    button = g_object_new (GIMP_TYPE_PATTERN_SELECT_BUTTON,
                           "pattern-name", pattern_name,
                           NULL);
263

264
  return button;
265 266 267
}

/**
268
 * gimp_pattern_select_button_get_pattern:
269 270 271 272 273 274
 * @button: A #GimpPatternSelectButton
 *
 * Retrieves the name of currently selected pattern.
 *
 * Returns: an internal copy of the pattern name which must not be freed.
 *
275
 * Since: 2.4
276
 */
277
const gchar *
278
gimp_pattern_select_button_get_pattern (GimpPatternSelectButton *button)
279 280 281
{
  GimpPatternSelectButtonPrivate *priv;

282
  g_return_val_if_fail (GIMP_IS_PATTERN_SELECT_BUTTON (button), NULL);
283

284
  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
285 286 287 288
  return priv->pattern_name;
}

/**
289
 * gimp_pattern_select_button_set_pattern:
290
 * @button: A #GimpPatternSelectButton
291 292 293 294
 * @pattern_name: Pattern name to set; %NULL means no change.
 *
 * Sets the current pattern for the pattern select button.
 *
295
 * Since: 2.4
296 297
 */
void
298 299
gimp_pattern_select_button_set_pattern (GimpPatternSelectButton *button,
                                        const gchar             *pattern_name)
300 301 302
{
  GimpSelectButton *select_button;

303
  g_return_if_fail (GIMP_IS_PATTERN_SELECT_BUTTON (button));
304

305
  select_button = GIMP_SELECT_BUTTON (button);
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333

  if (select_button->temp_callback)
    {
      gimp_patterns_set_popup (select_button->temp_callback, pattern_name);
    }
  else
    {
      gchar  *name;
      gint    width;
      gint    height;
      gint    bytes;
      gint    mask_data_size;
      guint8 *mask_data;

      if (pattern_name && *pattern_name)
        name = g_strdup (pattern_name);
      else
        name = gimp_context_get_pattern ();

      if (gimp_pattern_get_pixels (name,
                                   &width,
                                   &height,
                                   &bytes,
                                   &mask_data_size,
                                   &mask_data))
        {
          gimp_pattern_select_button_callback (name,
                                               width, height, bytes, mask_data,
334
                                               FALSE, button);
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370

          g_free (mask_data);
        }

      g_free (name);
    }
}


/*  private functions  */

static void
gimp_pattern_select_button_finalize (GObject *object)
{
  GimpPatternSelectButtonPrivate *priv;

  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (object);

  g_free (priv->pattern_name);
  priv->pattern_name = NULL;

  g_free (priv->mask_data);
  priv->mask_data = NULL;

  g_free (priv->title);
  priv->title = NULL;

  G_OBJECT_CLASS (gimp_pattern_select_button_parent_class)->finalize (object);
}

static void
gimp_pattern_select_button_set_property (GObject      *object,
                                         guint         property_id,
                                         const GValue *value,
                                         GParamSpec   *pspec)
{
371
  GimpPatternSelectButton        *button;
372 373
  GimpPatternSelectButtonPrivate *priv;

374 375
  button = GIMP_PATTERN_SELECT_BUTTON (object);
  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
376 377 378 379 380 381 382

  switch (property_id)
    {
    case PROP_TITLE:
      priv->title = g_value_dup_string (value);
      break;
    case PROP_PATTERN_NAME:
383 384
      gimp_pattern_select_button_set_pattern (button,
                                              g_value_get_string (value));
385 386 387 388 389 390 391 392 393 394 395 396 397
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
gimp_pattern_select_button_get_property (GObject    *object,
                                         guint       property_id,
                                         GValue     *value,
                                         GParamSpec *pspec)
{
398
  GimpPatternSelectButton        *button;
399 400
  GimpPatternSelectButtonPrivate *priv;

401 402
  button = GIMP_PATTERN_SELECT_BUTTON (object);
  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426

  switch (property_id)
    {
    case PROP_TITLE:
      g_value_set_string (value, priv->title);
      break;
    case PROP_PATTERN_NAME:
      g_value_set_string (value, priv->pattern_name);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
gimp_pattern_select_button_callback (const gchar  *pattern_name,
                                     gint          width,
                                     gint          height,
                                     gint          bytes,
                                     const guchar *mask_data,
                                     gboolean      dialog_closing,
                                     gpointer      user_data)
{
427
  GimpPatternSelectButton        *button;
428 429 430
  GimpPatternSelectButtonPrivate *priv;
  GimpSelectButton               *select_button;

431
  button = GIMP_PATTERN_SELECT_BUTTON (user_data);
432

433 434
  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
  select_button = GIMP_SELECT_BUTTON (button);
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450

  g_free (priv->pattern_name);
  g_free (priv->mask_data);

  priv->pattern_name = g_strdup (pattern_name);
  priv->width        = width;
  priv->height       = height;
  priv->bytes        = bytes;
  priv->mask_data    = g_memdup (mask_data, width * height * bytes);

  gimp_pattern_select_preview_update (priv->preview,
                                      width, height, bytes, mask_data);

  if (dialog_closing)
    select_button->temp_callback = NULL;

451
  g_signal_emit (button, pattern_button_signals[PATTERN_SET], 0,
452
                 pattern_name, width, height, bytes, dialog_closing);
453
  g_object_notify (G_OBJECT (button), "pattern-name");
454 455 456
}

static void
457
gimp_pattern_select_button_clicked (GimpPatternSelectButton *button)
458 459 460
{
  GimpPatternSelectButtonPrivate *priv;
  GimpSelectButton               *select_button;
461 462 463

  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
  select_button = GIMP_SELECT_BUTTON (button);
464 465 466 467 468 469 470 471 472 473 474 475

  if (select_button->temp_callback)
    {
      /*  calling gimp_patterns_set_popup() raises the dialog  */
      gimp_patterns_set_popup (select_button->temp_callback,
                               priv->pattern_name);
    }
  else
    {
      select_button->temp_callback =
        gimp_pattern_select_new (priv->title, priv->pattern_name,
                                 gimp_pattern_select_button_callback,
476
                                 button);
477 478 479 480
    }
}

static void
481
gimp_pattern_select_preview_resize (GimpPatternSelectButton *button)
482 483 484
{
  GimpPatternSelectButtonPrivate *priv;

485
  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
486 487 488 489 490 491 492 493 494 495 496 497

  if (priv->width > 0 && priv->height > 0)
    gimp_pattern_select_preview_update (priv->preview,
                                        priv->width,
                                        priv->height,
                                        priv->bytes,
                                        priv->mask_data);
}

static gboolean
gimp_pattern_select_preview_events (GtkWidget               *widget,
                                    GdkEvent                *event,
498
                                    GimpPatternSelectButton *button)
499 500 501 502
{
  GimpPatternSelectButtonPrivate *priv;
  GdkEventButton                 *bevent;

503
  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
504 505 506 507 508 509 510 511 512 513 514

  if (priv->mask_data)
    {
      switch (event->type)
        {
        case GDK_BUTTON_PRESS:
          bevent = (GdkEventButton *) event;

          if (bevent->button == 1)
            {
              gtk_grab_add (widget);
515
              gimp_pattern_select_button_open_popup (button,
516 517 518 519 520 521 522 523 524 525
                                                     bevent->x, bevent->y);
            }
          break;

        case GDK_BUTTON_RELEASE:
          bevent = (GdkEventButton *) event;

          if (bevent->button == 1)
            {
              gtk_grab_remove (widget);
526
              gimp_pattern_select_button_close_popup (button);
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
            }
          break;

        default:
          break;
        }
    }

  return FALSE;
}

static void
gimp_pattern_select_preview_update (GtkWidget    *preview,
                                    gint          width,
                                    gint          height,
                                    gint          bytes,
                                    const guchar *mask_data)
{
  GimpImageType type;

  switch (bytes)
    {
    case 1:  type = GIMP_GRAY_IMAGE;   break;
    case 2:  type = GIMP_GRAYA_IMAGE;  break;
    case 3:  type = GIMP_RGB_IMAGE;    break;
    case 4:  type = GIMP_RGBA_IMAGE;   break;
    default:
      return;
    }

  gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
                          0, 0, width, height,
                          type,
                          mask_data,
                          width * bytes);
}

static void
565
gimp_pattern_select_button_open_popup (GimpPatternSelectButton *button,
566 567 568 569 570 571
                                       gint                     x,
                                       gint                     y)
{
  GimpPatternSelectButtonPrivate *priv;
  GtkWidget                      *frame;
  GtkWidget                      *preview;
572 573
  GdkMonitor                    *monitor;
  GdkRectangle                   workarea;
574 575 576
  gint                            x_org;
  gint                            y_org;

577
  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
578 579

  if (priv->popup)
580
    gimp_pattern_select_button_close_popup (button);
581 582 583 584 585

  if (priv->width <= CELL_SIZE && priv->height <= CELL_SIZE)
    return;

  priv->popup = gtk_window_new (GTK_WINDOW_POPUP);
586
  gtk_window_set_type_hint (GTK_WINDOW (priv->popup), GDK_WINDOW_TYPE_HINT_DND);
587 588
  gtk_window_set_screen (GTK_WINDOW (priv->popup),
                         gtk_widget_get_screen (GTK_WIDGET (button)));
589 590 591 592 593 594 595 596 597 598 599 600

  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
  gtk_container_add (GTK_CONTAINER (priv->popup), frame);
  gtk_widget_show (frame);

  preview = gimp_preview_area_new ();
  gtk_widget_set_size_request (preview, priv->width, priv->height);
  gtk_container_add (GTK_CONTAINER (frame), preview);
  gtk_widget_show (preview);

  /* decide where to put the popup */
601 602
  gdk_window_get_origin (gtk_widget_get_window (priv->preview),
                         &x_org, &y_org);
603

604 605
  monitor = gimp_widget_get_monitor (GTK_WIDGET (button));
  gdk_monitor_get_workarea (monitor, &workarea);
606 607 608

  x = x_org + x - (priv->width  / 2);
  y = y_org + y - (priv->height / 2);
609 610 611

  x = CLAMP (x, workarea.x, workarea.x + workarea.width  - priv->width);
  y = CLAMP (y, workarea.y, workarea.y + workarea.height - priv->height);
612 613 614 615 616 617 618 619 620 621 622 623 624 625

  gtk_window_move (GTK_WINDOW (priv->popup), x, y);

  gtk_widget_show (priv->popup);

  /*  Draw the pattern  */
  gimp_pattern_select_preview_update (preview,
                                      priv->width,
                                      priv->height,
                                      priv->bytes,
                                      priv->mask_data);
}

static void
626
gimp_pattern_select_button_close_popup (GimpPatternSelectButton *button)
627 628 629
{
  GimpPatternSelectButtonPrivate *priv;

630
  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (button);
631 632 633 634 635 636 637 638 639

  if (priv->popup)
    {
      gtk_widget_destroy (priv->popup);
      priv->popup = NULL;
    }
}

static void
640
gimp_pattern_select_drag_data_received (GimpPatternSelectButton *button,
641 642 643 644 645 646 647
                                        GdkDragContext          *context,
                                        gint                     x,
                                        gint                     y,
                                        GtkSelectionData        *selection,
                                        guint                    info,
                                        guint                    time)
{
648
  gint   length = gtk_selection_data_get_length (selection);
649 650
  gchar *str;

651
  if (gtk_selection_data_get_format (selection) != 8 || length < 1)
652 653 654 655 656
    {
      g_warning ("Received invalid pattern data!");
      return;
    }

657 658
  str = g_strndup ((const gchar *) gtk_selection_data_get_data (selection),
                   length);
659 660 661 662 663 664 665 666 667 668 669 670

  if (g_utf8_validate (str, -1, NULL))
    {
      gint     pid;
      gpointer unused;
      gint     name_offset = 0;

      if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
          pid == gimp_getpid () && name_offset > 0)
        {
          gchar *name = str + name_offset;

671
          gimp_pattern_select_button_set_pattern (button, name);
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
        }
    }

  g_free (str);
}

static GtkWidget *
gimp_pattern_select_button_create_inside (GimpPatternSelectButton *pattern_button)
{
  GtkWidget                      *hbox;
  GtkWidget                      *frame;
  GtkWidget                      *button;
  GimpPatternSelectButtonPrivate *priv;

  priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (pattern_button);

688
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713

  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);

  priv->preview = gimp_preview_area_new ();
  gtk_widget_add_events (priv->preview,
                         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
  gtk_widget_set_size_request (priv->preview, CELL_SIZE, CELL_SIZE);
  gtk_container_add (GTK_CONTAINER (frame), priv->preview);

  g_signal_connect_swapped (priv->preview, "size-allocate",
                            G_CALLBACK (gimp_pattern_select_preview_resize),
                            pattern_button);
  g_signal_connect (priv->preview, "event",
                    G_CALLBACK (gimp_pattern_select_preview_events),
                    pattern_button);

  gtk_drag_dest_set (GTK_WIDGET (priv->preview),
                     GTK_DEST_DEFAULT_HIGHLIGHT |
                     GTK_DEST_DEFAULT_MOTION |
                     GTK_DEST_DEFAULT_DROP,
                     &target, 1,
                     GDK_ACTION_COPY);

714 715 716
  g_signal_connect_swapped (priv->preview, "drag-data-received",
                            G_CALLBACK (gimp_pattern_select_drag_data_received),
                            pattern_button);
717 718 719 720 721 722 723 724 725 726 727 728

  button = gtk_button_new_with_mnemonic (_("_Browse..."));
  gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);

  g_signal_connect_swapped (button, "clicked",
                            G_CALLBACK (gimp_pattern_select_button_clicked),
                            pattern_button);

  gtk_widget_show_all (hbox);

  return hbox;
}