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

« back to all changes in this revision

Viewing changes to libgimp/gimpgradientselectbutton.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
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpgradientselectbutton.c
 
5
 * Copyright (C) 1998 Andy Thomas
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Library General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the
 
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#include <gtk/gtk.h>
 
26
 
 
27
#include "libgimpwidgets/gimpwidgets.h"
 
28
 
 
29
#include "gimp.h"
 
30
 
 
31
#include "gimpuitypes.h"
 
32
#include "gimpgradientselectbutton.h"
 
33
#include "gimpuimarshal.h"
 
34
 
 
35
#include "libgimp-intl.h"
 
36
 
 
37
 
 
38
#define CELL_HEIGHT 18
 
39
#define CELL_WIDTH  84
 
40
 
 
41
 
 
42
#define GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_GRADIENT_SELECT_BUTTON, GimpGradientSelectButtonPrivate))
 
43
 
 
44
typedef struct _GimpGradientSelectButtonPrivate GimpGradientSelectButtonPrivate;
 
45
 
 
46
struct _GimpGradientSelectButtonPrivate
 
47
{
 
48
  gchar     *title;
 
49
 
 
50
  gchar     *gradient_name;      /* Local copy */
 
51
  gint       sample_size;
 
52
  gboolean   reverse;
 
53
  gint       n_samples;
 
54
  gdouble   *gradient_data;      /* Local copy */
 
55
 
 
56
  GtkWidget *inside;
 
57
  GtkWidget *preview;
 
58
};
 
59
 
 
60
enum
 
61
{
 
62
  GRADIENT_SET,
 
63
  LAST_SIGNAL
 
64
};
 
65
 
 
66
enum
 
67
{
 
68
  PROP_0,
 
69
  PROP_TITLE,
 
70
  PROP_GRADIENT_NAME
 
71
};
 
72
 
 
73
 
 
74
/*  local function prototypes  */
 
75
 
 
76
static void   gimp_gradient_select_button_finalize     (GObject      *object);
 
77
 
 
78
static void   gimp_gradient_select_button_set_property (GObject      *object,
 
79
                                                        guint         property_id,
 
80
                                                        const GValue *value,
 
81
                                                        GParamSpec   *pspec);
 
82
static void   gimp_gradient_select_button_get_property (GObject      *object,
 
83
                                                        guint         property_id,
 
84
                                                        GValue       *value,
 
85
                                                        GParamSpec   *pspec);
 
86
 
 
87
static void   gimp_gradient_select_button_clicked  (GimpGradientSelectButton *button);
 
88
 
 
89
static void   gimp_gradient_select_button_callback (const gchar   *gradient_name,
 
90
                                                    gint           n_samples,
 
91
                                                    const gdouble *gradient_data,
 
92
                                                    gboolean       dialog_closing,
 
93
                                                    gpointer       user_data);
 
94
 
 
95
static void gimp_gradient_select_preview_size_allocate
 
96
                                                 (GtkWidget                *widget,
 
97
                                                  GtkAllocation            *allocation,
 
98
                                                  GimpGradientSelectButton *button);
 
99
static void gimp_gradient_select_preview_expose  (GtkWidget                *preview,
 
100
                                                  GdkEventExpose           *event,
 
101
                                                  GimpGradientSelectButton *button);
 
102
 
 
103
static void   gimp_gradient_select_drag_data_received (GimpGradientSelectButton *button,
 
104
                                                       GdkDragContext           *context,
 
105
                                                       gint                      x,
 
106
                                                       gint                      y,
 
107
                                                       GtkSelectionData         *selection,
 
108
                                                       guint                     info,
 
109
                                                       guint                     time);
 
110
 
 
111
static GtkWidget * gimp_gradient_select_button_create_inside (GimpGradientSelectButton *button);
 
112
 
 
113
 
 
114
static const GtkTargetEntry target = { "application/x-gimp-gradient-name", 0 };
 
115
 
 
116
static guint gradient_button_signals[LAST_SIGNAL] = { 0 };
 
117
 
 
118
 
 
119
G_DEFINE_TYPE (GimpGradientSelectButton, gimp_gradient_select_button,
 
120
               GIMP_TYPE_SELECT_BUTTON)
 
121
 
 
122
 
 
123
static void
 
124
gimp_gradient_select_button_class_init (GimpGradientSelectButtonClass *klass)
 
125
{
 
126
  GObjectClass          *object_class        = G_OBJECT_CLASS (klass);
 
127
  GimpSelectButtonClass *select_button_class = GIMP_SELECT_BUTTON_CLASS (klass);
 
128
 
 
129
  object_class->finalize     = gimp_gradient_select_button_finalize;
 
130
  object_class->set_property = gimp_gradient_select_button_set_property;
 
131
  object_class->get_property = gimp_gradient_select_button_get_property;
 
132
 
 
133
  select_button_class->select_destroy = gimp_gradient_select_destroy;
 
134
 
 
135
  klass->gradient_set = NULL;
 
136
 
 
137
  /**
 
138
   * GimpGradientSelectButton:title:
 
139
   *
 
140
   * The title to be used for the gradient selection popup dialog.
 
141
   *
 
142
   * Since: GIMP 2.4
 
143
   */
 
144
  g_object_class_install_property (object_class, PROP_TITLE,
 
145
                                   g_param_spec_string ("title",
 
146
                                                        "Title",
 
147
                                                        "The title to be used for the gradient selection popup dialog",
 
148
                                                        _("Gradient Selection"),
 
149
                                                        GIMP_PARAM_READWRITE |
 
150
                                                        G_PARAM_CONSTRUCT_ONLY));
 
151
 
 
152
  /**
 
153
   * GimpGradientSelectButton:gradient-name:
 
154
   *
 
155
   * The name of the currently selected gradient.
 
156
   *
 
157
   * Since: GIMP 2.4
 
158
   */
 
159
  g_object_class_install_property (object_class, PROP_GRADIENT_NAME,
 
160
                                   g_param_spec_string ("gradient-name",
 
161
                                                        "Gradient name",
 
162
                                                        "The name of the currently selected gradient",
 
163
                                                        NULL,
 
164
                                                        GIMP_PARAM_READWRITE));
 
165
 
 
166
  /**
 
167
   * GimpGradientSelectButton::gradient-set:
 
168
   * @widget: the object which received the signal.
 
169
   * @gradient_name: the name of the currently selected gradient.
 
170
   * @width: width of the gradient
 
171
   * @grad_data: gradient data
 
172
   * @dialog_closing: whether the dialog was closed or not.
 
173
   *
 
174
   * The ::gradient-set signal is emitted when the user selects a gradient.
 
175
   *
 
176
   * Since: GIMP 2.4
 
177
   */
 
178
  gradient_button_signals[GRADIENT_SET] =
 
179
    g_signal_new ("gradient-set",
 
180
                  G_TYPE_FROM_CLASS (klass),
 
181
                  G_SIGNAL_RUN_FIRST,
 
182
                  G_STRUCT_OFFSET (GimpGradientSelectButtonClass, gradient_set),
 
183
                  NULL, NULL,
 
184
                  _gimpui_marshal_VOID__STRING_INT_POINTER_BOOLEAN,
 
185
                  G_TYPE_NONE, 4,
 
186
                  G_TYPE_STRING,
 
187
                  G_TYPE_INT,
 
188
                  G_TYPE_POINTER,
 
189
                  G_TYPE_BOOLEAN);
 
190
 
 
191
  g_type_class_add_private (object_class,
 
192
                            sizeof (GimpGradientSelectButtonPrivate));
 
193
}
 
194
 
 
195
static void
 
196
gimp_gradient_select_button_init (GimpGradientSelectButton *button)
 
197
{
 
198
  GimpGradientSelectButtonPrivate *priv;
 
199
 
 
200
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
201
 
 
202
  priv->gradient_name = gimp_context_get_gradient ();
 
203
  priv->sample_size = CELL_WIDTH;
 
204
  priv->reverse = FALSE;
 
205
 
 
206
  priv->inside = gimp_gradient_select_button_create_inside (button);
 
207
  gtk_container_add (GTK_CONTAINER (button), priv->inside);
 
208
}
 
209
 
 
210
/**
 
211
 * gimp_gradient_select_button_new:
 
212
 * @title:         Title of the dialog to use or %NULL to use the default title.
 
213
 * @gradient_name: Initial gradient name.
 
214
 *
 
215
 * Creates a new #GtkWidget that completely controls the selection of
 
216
 * a gradient.  This widget is suitable for placement in a table in a
 
217
 * plug-in dialog.
 
218
 *
 
219
 * Returns: A #GtkWidget that you can use in your UI.
 
220
 *
 
221
 * Since: GIMP 2.4
 
222
 */
 
223
GtkWidget *
 
224
gimp_gradient_select_button_new (const gchar *title,
 
225
                                 const gchar *gradient_name)
 
226
{
 
227
  GtkWidget *button;
 
228
 
 
229
  if (title)
 
230
    button = g_object_new (GIMP_TYPE_GRADIENT_SELECT_BUTTON,
 
231
                                    "title",         title,
 
232
                                    "gradient-name", gradient_name,
 
233
                                    NULL);
 
234
  else
 
235
    button = g_object_new (GIMP_TYPE_GRADIENT_SELECT_BUTTON,
 
236
                                    "gradient-name", gradient_name,
 
237
                                    NULL);
 
238
 
 
239
  return button;
 
240
}
 
241
 
 
242
/**
 
243
 * gimp_gradient_select_button_get_gradient:
 
244
 * @button: A #GimpGradientSelectButton
 
245
 *
 
246
 * Retrieves the name of currently selected gradient.
 
247
 *
 
248
 * Returns: an internal copy of the gradient name which must not be freed.
 
249
 *
 
250
 * Since: GIMP 2.4
 
251
 */
 
252
const gchar *
 
253
gimp_gradient_select_button_get_gradient (GimpGradientSelectButton *button)
 
254
{
 
255
  GimpGradientSelectButtonPrivate *priv;
 
256
 
 
257
  g_return_val_if_fail (GIMP_IS_GRADIENT_SELECT_BUTTON (button), NULL);
 
258
 
 
259
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
260
  return priv->gradient_name;
 
261
}
 
262
 
 
263
/**
 
264
 * gimp_gradient_select_button_set_gradient:
 
265
 * @button: A #GimpGradientSelectButton
 
266
 * @gradient_name: Gradient name to set.
 
267
 *
 
268
 * Sets the current gradient for the gradient select button.
 
269
 *
 
270
 * Since: GIMP 2.4
 
271
 */
 
272
void
 
273
gimp_gradient_select_button_set_gradient (GimpGradientSelectButton *button,
 
274
                                          const gchar              *gradient_name)
 
275
{
 
276
  GimpGradientSelectButtonPrivate *priv;
 
277
  GimpSelectButton                *select_button;
 
278
 
 
279
  g_return_if_fail (GIMP_IS_GRADIENT_SELECT_BUTTON (button));
 
280
 
 
281
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
282
  select_button = GIMP_SELECT_BUTTON (button);
 
283
 
 
284
  if (select_button->temp_callback)
 
285
    {
 
286
      gimp_gradients_set_popup (select_button->temp_callback, gradient_name);
 
287
    }
 
288
  else
 
289
    {
 
290
      gchar   *name;
 
291
      gdouble *samples;
 
292
      gint     n_samples;
 
293
 
 
294
      if (gradient_name && *gradient_name)
 
295
        name = g_strdup (gradient_name);
 
296
      else
 
297
        name = gimp_context_get_gradient ();
 
298
 
 
299
      if (gimp_gradient_get_uniform_samples (name,
 
300
                                             priv->sample_size,
 
301
                                             priv->reverse,
 
302
                                             &n_samples,
 
303
                                             &samples))
 
304
        {
 
305
          gimp_gradient_select_button_callback (name,
 
306
                                                n_samples, samples,
 
307
                                                FALSE, button);
 
308
 
 
309
          g_free (samples);
 
310
        }
 
311
 
 
312
      g_free (name);
 
313
    }
 
314
}
 
315
 
 
316
 
 
317
/*  private functions  */
 
318
 
 
319
static void
 
320
gimp_gradient_select_button_finalize (GObject *object)
 
321
{
 
322
  GimpGradientSelectButtonPrivate *priv;
 
323
 
 
324
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (object);
 
325
 
 
326
  g_free (priv->gradient_name);
 
327
  priv->gradient_name = NULL;
 
328
 
 
329
  g_free (priv->gradient_data);
 
330
  priv->gradient_data = NULL;
 
331
 
 
332
  g_free (priv->title);
 
333
  priv->title = NULL;
 
334
 
 
335
  G_OBJECT_CLASS (gimp_gradient_select_button_parent_class)->finalize (object);
 
336
}
 
337
 
 
338
static void
 
339
gimp_gradient_select_button_set_property (GObject      *object,
 
340
                                          guint         property_id,
 
341
                                          const GValue *value,
 
342
                                          GParamSpec   *pspec)
 
343
{
 
344
  GimpGradientSelectButton        *button;
 
345
  GimpGradientSelectButtonPrivate *priv;
 
346
 
 
347
  button = GIMP_GRADIENT_SELECT_BUTTON (object);
 
348
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
349
 
 
350
  switch (property_id)
 
351
    {
 
352
    case PROP_TITLE:
 
353
      priv->title = g_value_dup_string (value);
 
354
      break;
 
355
    case PROP_GRADIENT_NAME:
 
356
      gimp_gradient_select_button_set_gradient (button,
 
357
                                                g_value_get_string (value));
 
358
      break;
 
359
    default:
 
360
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
361
      break;
 
362
    }
 
363
}
 
364
 
 
365
static void
 
366
gimp_gradient_select_button_get_property (GObject    *object,
 
367
                                          guint       property_id,
 
368
                                          GValue     *value,
 
369
                                          GParamSpec *pspec)
 
370
{
 
371
  GimpGradientSelectButton        *button;
 
372
  GimpGradientSelectButtonPrivate *priv;
 
373
 
 
374
  button = GIMP_GRADIENT_SELECT_BUTTON (object);
 
375
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
376
 
 
377
  switch (property_id)
 
378
    {
 
379
    case PROP_TITLE:
 
380
      g_value_set_string (value, priv->title);
 
381
      break;
 
382
    case PROP_GRADIENT_NAME:
 
383
      g_value_set_string (value, priv->gradient_name);
 
384
      break;
 
385
    default:
 
386
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
387
      break;
 
388
    }
 
389
}
 
390
 
 
391
static void
 
392
gimp_gradient_select_button_callback (const gchar   *gradient_name,
 
393
                                      gint           n_samples,
 
394
                                      const gdouble *gradient_data,
 
395
                                      gboolean       dialog_closing,
 
396
                                      gpointer       user_data)
 
397
{
 
398
  GimpGradientSelectButton        *button;
 
399
  GimpGradientSelectButtonPrivate *priv;
 
400
  GimpSelectButton                *select_button;
 
401
 
 
402
  button = GIMP_GRADIENT_SELECT_BUTTON (user_data);
 
403
 
 
404
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
405
  select_button = GIMP_SELECT_BUTTON (button);
 
406
 
 
407
  g_free (priv->gradient_name);
 
408
  g_free (priv->gradient_data);
 
409
 
 
410
  priv->gradient_name = g_strdup (gradient_name);
 
411
  priv->n_samples     = n_samples;
 
412
  priv->gradient_data = g_memdup (gradient_data, n_samples * sizeof (gdouble));
 
413
 
 
414
  gtk_widget_queue_draw (priv->preview);
 
415
 
 
416
  if (dialog_closing)
 
417
    select_button->temp_callback = NULL;
 
418
 
 
419
  g_signal_emit (button, gradient_button_signals[GRADIENT_SET], 0,
 
420
                 gradient_name, n_samples, gradient_data, dialog_closing);
 
421
  g_object_notify (G_OBJECT (button), "gradient-name");
 
422
}
 
423
 
 
424
static void
 
425
gimp_gradient_select_button_clicked (GimpGradientSelectButton *button)
 
426
{
 
427
  GimpGradientSelectButtonPrivate *priv;
 
428
  GimpSelectButton                *select_button;
 
429
 
 
430
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
431
  select_button = GIMP_SELECT_BUTTON (button);
 
432
 
 
433
  if (select_button->temp_callback)
 
434
    {
 
435
      /*  calling gimp_gradients_set_popup() raises the dialog  */
 
436
      gimp_gradients_set_popup (select_button->temp_callback,
 
437
                                priv->gradient_name);
 
438
    }
 
439
  else
 
440
    {
 
441
      select_button->temp_callback =
 
442
        gimp_gradient_select_new (priv->title, priv->gradient_name,
 
443
                                  priv->sample_size,
 
444
                                  gimp_gradient_select_button_callback,
 
445
                                  button);
 
446
    }
 
447
}
 
448
 
 
449
static void
 
450
gimp_gradient_select_preview_size_allocate (GtkWidget                *widget,
 
451
                                            GtkAllocation            *allocation,
 
452
                                            GimpGradientSelectButton *button)
 
453
{
 
454
  gdouble                         *samples;
 
455
  gint                             n_samples;
 
456
  GimpGradientSelectButtonPrivate *priv;
 
457
 
 
458
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
459
 
 
460
  if (gimp_gradient_get_uniform_samples (priv->gradient_name,
 
461
                                         allocation->width,
 
462
                                         priv->reverse,
 
463
                                         &n_samples,
 
464
                                         &samples))
 
465
    {
 
466
      g_free (priv->gradient_data);
 
467
 
 
468
      priv->sample_size   = allocation->width;
 
469
      priv->n_samples     = n_samples;
 
470
      priv->gradient_data = samples;
 
471
    }
 
472
}
 
473
 
 
474
static void
 
475
gimp_gradient_select_preview_expose (GtkWidget                *widget,
 
476
                                     GdkEventExpose           *event,
 
477
                                     GimpGradientSelectButton *button)
 
478
{
 
479
  const gdouble                   *src;
 
480
  guchar                          *p0;
 
481
  guchar                          *p1;
 
482
  guchar                          *even;
 
483
  guchar                          *odd;
 
484
  gint                             width;
 
485
  gint                             x, y;
 
486
  GimpGradientSelectButtonPrivate *priv;
 
487
 
 
488
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
 
489
 
 
490
  src = priv->gradient_data;
 
491
  if (! src)
 
492
    return;
 
493
 
 
494
  width = priv->n_samples / 4;
 
495
 
 
496
  p0 = even = g_malloc (width * 3);
 
497
  p1 = odd  = g_malloc (width * 3);
 
498
 
 
499
  for (x = 0; x < width; x++)
 
500
    {
 
501
      gdouble  r, g, b, a;
 
502
      gdouble  c0, c1;
 
503
 
 
504
      r = src[x * 4 + 0];
 
505
      g = src[x * 4 + 1];
 
506
      b = src[x * 4 + 2];
 
507
      a = src[x * 4 + 3];
 
508
 
 
509
      if ((x / GIMP_CHECK_SIZE_SM) & 1)
 
510
        {
 
511
          c0 = GIMP_CHECK_LIGHT;
 
512
          c1 = GIMP_CHECK_DARK;
 
513
        }
 
514
      else
 
515
        {
 
516
          c0 = GIMP_CHECK_DARK;
 
517
          c1 = GIMP_CHECK_LIGHT;
 
518
        }
 
519
 
 
520
      *p0++ = (c0 + (r - c0) * a) * 255.0;
 
521
      *p0++ = (c0 + (g - c0) * a) * 255.0;
 
522
      *p0++ = (c0 + (b - c0) * a) * 255.0;
 
523
 
 
524
      *p1++ = (c1 + (r - c1) * a) * 255.0;
 
525
      *p1++ = (c1 + (g - c1) * a) * 255.0;
 
526
      *p1++ = (c1 + (b - c1) * a) * 255.0;
 
527
    }
 
528
 
 
529
  for (y = event->area.y; y < event->area.y + event->area.height; y++)
 
530
    {
 
531
      guchar *buf = ((y / GIMP_CHECK_SIZE_SM) & 1) ? odd : even;
 
532
 
 
533
      gdk_draw_rgb_image_dithalign (widget->window,
 
534
                                    widget->style->fg_gc[widget->state],
 
535
                                    event->area.x, y,
 
536
                                    event->area.width, 1,
 
537
                                    GDK_RGB_DITHER_MAX,
 
538
                                    buf + event->area.x * 3,
 
539
                                    width * 3,
 
540
                                    - event->area.x, - y);
 
541
    }
 
542
 
 
543
  g_free (odd);
 
544
  g_free (even);
 
545
}
 
546
 
 
547
static void
 
548
gimp_gradient_select_drag_data_received (GimpGradientSelectButton *button,
 
549
                                        GdkDragContext            *context,
 
550
                                        gint                       x,
 
551
                                        gint                       y,
 
552
                                        GtkSelectionData          *selection,
 
553
                                        guint                      info,
 
554
                                        guint                      time)
 
555
{
 
556
  gchar *str;
 
557
 
 
558
  if ((selection->format != 8) || (selection->length < 1))
 
559
    {
 
560
      g_warning ("Received invalid gradient data!");
 
561
      return;
 
562
    }
 
563
 
 
564
  str = g_strndup ((const gchar *) selection->data, selection->length);
 
565
 
 
566
  if (g_utf8_validate (str, -1, NULL))
 
567
    {
 
568
      gint     pid;
 
569
      gpointer unused;
 
570
      gint     name_offset = 0;
 
571
 
 
572
      if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
 
573
          pid == gimp_getpid () && name_offset > 0)
 
574
        {
 
575
          gchar *name = str + name_offset;
 
576
 
 
577
          gimp_gradient_select_button_set_gradient (button, name);
 
578
        }
 
579
    }
 
580
 
 
581
  g_free (str);
 
582
}
 
583
 
 
584
static GtkWidget *
 
585
gimp_gradient_select_button_create_inside (GimpGradientSelectButton *gradient_button)
 
586
{
 
587
  GtkWidget                       *button;
 
588
  GimpGradientSelectButtonPrivate *priv;
 
589
 
 
590
  priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (gradient_button);
 
591
 
 
592
  gtk_widget_push_composite_child ();
 
593
 
 
594
  button = gtk_button_new ();
 
595
 
 
596
  priv->preview = gtk_drawing_area_new ();
 
597
  gtk_widget_set_size_request (priv->preview, CELL_WIDTH, CELL_HEIGHT);
 
598
  gtk_container_add (GTK_CONTAINER (button), priv->preview);
 
599
 
 
600
  g_signal_connect (priv->preview, "size-allocate",
 
601
                    G_CALLBACK (gimp_gradient_select_preview_size_allocate),
 
602
                    gradient_button);
 
603
 
 
604
  g_signal_connect (priv->preview, "expose-event",
 
605
                    G_CALLBACK (gimp_gradient_select_preview_expose),
 
606
                    gradient_button);
 
607
 
 
608
  gtk_widget_show_all (button);
 
609
 
 
610
  g_signal_connect_swapped (button, "clicked",
 
611
                            G_CALLBACK (gimp_gradient_select_button_clicked),
 
612
                            gradient_button);
 
613
 
 
614
  gtk_drag_dest_set (GTK_WIDGET (button),
 
615
                     GTK_DEST_DEFAULT_HIGHLIGHT |
 
616
                     GTK_DEST_DEFAULT_MOTION |
 
617
                     GTK_DEST_DEFAULT_DROP,
 
618
                     &target, 1,
 
619
                     GDK_ACTION_COPY);
 
620
 
 
621
  g_signal_connect_swapped (button, "drag-data-received",
 
622
                            G_CALLBACK (gimp_gradient_select_drag_data_received),
 
623
                            gradient_button);
 
624
 
 
625
  gtk_widget_pop_composite_child ();
 
626
 
 
627
  return button;
 
628
}