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

« back to all changes in this revision

Viewing changes to app/widgets/gimpdnd.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-1997 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
45
45
 
46
46
#include "vectors/gimpvectors.h"
47
47
 
 
48
/*  #define DEBUG_DND  */
 
49
 
48
50
#include "gimpdnd.h"
 
51
#include "gimpdnd-xds.h"
 
52
#include "gimppixbuf.h"
 
53
#include "gimpselectiondata.h"
49
54
#include "gimpview.h"
50
 
#include "gimpselectiondata.h"
 
55
#include "gimpviewrendererimage.h"
51
56
 
52
57
#include "gimp-intl.h"
53
58
 
54
59
 
55
 
#define DRAG_PREVIEW_SIZE 32
56
 
#define DRAG_ICON_OFFSET  -8
 
60
#define DRAG_PREVIEW_SIZE  GIMP_VIEW_SIZE_LARGE
 
61
#define DRAG_ICON_OFFSET   -8
57
62
 
58
 
/* #define DEBUG_DND */
59
63
 
60
64
#ifdef DEBUG_DND
61
65
#define D(stmnt) stmnt
68
72
                                             GCallback         get_data_func,
69
73
                                             gpointer          get_data_data);
70
74
typedef void        (* GimpDndDragDataFunc) (GtkWidget        *widget,
 
75
                                             GdkDragContext   *context,
71
76
                                             GCallback         get_data_func,
72
77
                                             gpointer          get_data_data,
73
 
                                             GtkSelectionData *selection,
74
 
                                             GdkAtom           atom);
 
78
                                             GtkSelectionData *selection);
75
79
typedef gboolean    (* GimpDndDropDataFunc) (GtkWidget        *widget,
 
80
                                             gint              x,
 
81
                                             gint              y,
76
82
                                             GCallback         set_data_func,
77
83
                                             gpointer          set_data_data,
78
84
                                             GtkSelectionData *selection);
84
90
{
85
91
  GtkTargetEntry       target_entry;
86
92
 
87
 
  gchar               *get_data_func_name;
88
 
  gchar               *get_data_data_name;
 
93
  const gchar         *get_data_func_name;
 
94
  const gchar         *get_data_data_name;
89
95
 
90
 
  gchar               *set_data_func_name;
91
 
  gchar               *set_data_data_name;
 
96
  const gchar         *set_data_func_name;
 
97
  const gchar         *set_data_data_name;
92
98
 
93
99
  GimpDndGetIconFunc   get_icon_func;
94
100
  GimpDndDragDataFunc  get_data_func;
99
105
static GtkWidget * gimp_dnd_get_viewable_icon  (GtkWidget        *widget,
100
106
                                                GCallback         get_viewable_func,
101
107
                                                gpointer          get_viewable_data);
 
108
static GtkWidget * gimp_dnd_get_component_icon (GtkWidget        *widget,
 
109
                                                GCallback         get_comp_func,
 
110
                                                gpointer          get_comp_data);
102
111
static GtkWidget * gimp_dnd_get_color_icon     (GtkWidget        *widget,
103
112
                                                GCallback         get_color_func,
104
113
                                                gpointer          get_color_data);
105
114
 
106
115
static void        gimp_dnd_get_uri_list_data  (GtkWidget        *widget,
 
116
                                                GdkDragContext   *context,
107
117
                                                GCallback         get_uri_list_func,
108
118
                                                gpointer          get_uri_list_data,
109
 
                                                GtkSelectionData *selection,
110
 
                                                GdkAtom           atom);
 
119
                                                GtkSelectionData *selection);
111
120
static gboolean    gimp_dnd_set_uri_list_data  (GtkWidget        *widget,
 
121
                                                gint              x,
 
122
                                                gint              y,
112
123
                                                GCallback         set_uri_list_func,
113
124
                                                gpointer          set_uri_list_data,
114
125
                                                GtkSelectionData *selection);
115
126
 
 
127
static void        gimp_dnd_get_xds_data       (GtkWidget        *widget,
 
128
                                                GdkDragContext   *context,
 
129
                                                GCallback         get_image_func,
 
130
                                                gpointer          get_image_data,
 
131
                                                GtkSelectionData *selection);
 
132
 
116
133
static void        gimp_dnd_get_color_data     (GtkWidget        *widget,
 
134
                                                GdkDragContext   *context,
117
135
                                                GCallback         get_color_func,
118
136
                                                gpointer          get_color_data,
119
 
                                                GtkSelectionData *selection,
120
 
                                                GdkAtom           atom);
 
137
                                                GtkSelectionData *selection);
121
138
static gboolean    gimp_dnd_set_color_data     (GtkWidget        *widget,
 
139
                                                gint              x,
 
140
                                                gint              y,
122
141
                                                GCallback         set_color_func,
123
142
                                                gpointer          set_color_data,
124
143
                                                GtkSelectionData *selection);
125
144
 
126
145
static void        gimp_dnd_get_stream_data    (GtkWidget        *widget,
 
146
                                                GdkDragContext   *context,
127
147
                                                GCallback         get_stream_func,
128
148
                                                gpointer          get_stream_data,
129
 
                                                GtkSelectionData *selection,
130
 
                                                GdkAtom           atom);
 
149
                                                GtkSelectionData *selection);
131
150
static gboolean    gimp_dnd_set_stream_data    (GtkWidget        *widget,
 
151
                                                gint              x,
 
152
                                                gint              y,
132
153
                                                GCallback         set_stream_func,
133
154
                                                gpointer          set_stream_data,
134
155
                                                GtkSelectionData *selection);
135
156
 
 
157
static void        gimp_dnd_get_pixbuf_data    (GtkWidget        *widget,
 
158
                                                GdkDragContext   *context,
 
159
                                                GCallback         get_pixbuf_func,
 
160
                                                gpointer          get_pixbuf_data,
 
161
                                                GtkSelectionData *selection);
 
162
static gboolean    gimp_dnd_set_pixbuf_data    (GtkWidget        *widget,
 
163
                                                gint              x,
 
164
                                                gint              y,
 
165
                                                GCallback         set_pixbuf_func,
 
166
                                                gpointer          set_pixbuf_data,
 
167
                                                GtkSelectionData *selection);
 
168
static void        gimp_dnd_get_component_data (GtkWidget        *widget,
 
169
                                                GdkDragContext   *context,
 
170
                                                GCallback         get_comp_func,
 
171
                                                gpointer          get_comp_data,
 
172
                                                GtkSelectionData *selection);
 
173
static gboolean    gimp_dnd_set_component_data (GtkWidget        *widget,
 
174
                                                gint              x,
 
175
                                                gint              y,
 
176
                                                GCallback         set_comp_func,
 
177
                                                gpointer          set_comp_data,
 
178
                                                GtkSelectionData *selection);
 
179
 
136
180
static void        gimp_dnd_get_image_data     (GtkWidget        *widget,
 
181
                                                GdkDragContext   *context,
137
182
                                                GCallback         get_image_func,
138
183
                                                gpointer          get_image_data,
139
 
                                                GtkSelectionData *selection,
140
 
                                                GdkAtom           atom);
 
184
                                                GtkSelectionData *selection);
141
185
static gboolean    gimp_dnd_set_image_data     (GtkWidget        *widget,
 
186
                                                gint              x,
 
187
                                                gint              y,
142
188
                                                GCallback         set_image_func,
143
189
                                                gpointer          set_image_data,
144
190
                                                GtkSelectionData *selection);
145
191
 
146
192
static void        gimp_dnd_get_item_data      (GtkWidget        *widget,
 
193
                                                GdkDragContext   *context,
147
194
                                                GCallback         get_item_func,
148
195
                                                gpointer          get_item_data,
149
 
                                                GtkSelectionData *selection,
150
 
                                                GdkAtom           atom);
 
196
                                                GtkSelectionData *selection);
151
197
static gboolean    gimp_dnd_set_item_data      (GtkWidget        *widget,
 
198
                                                gint              x,
 
199
                                                gint              y,
152
200
                                                GCallback         set_item_func,
153
201
                                                gpointer          set_item_data,
154
202
                                                GtkSelectionData *selection);
155
203
 
156
 
static void        gimp_dnd_get_data_data      (GtkWidget        *widget,
157
 
                                                GCallback         get_data_func,
158
 
                                                gpointer          get_data_data,
159
 
                                                GtkSelectionData *selection,
160
 
                                                GdkAtom           atom);
 
204
static void        gimp_dnd_get_object_data    (GtkWidget        *widget,
 
205
                                                GdkDragContext   *context,
 
206
                                                GCallback         get_object_func,
 
207
                                                gpointer          get_object_data,
 
208
                                                GtkSelectionData *selection);
161
209
 
162
210
static gboolean    gimp_dnd_set_brush_data     (GtkWidget        *widget,
 
211
                                                gint              x,
 
212
                                                gint              y,
163
213
                                                GCallback         set_brush_func,
164
214
                                                gpointer          set_brush_data,
165
215
                                                GtkSelectionData *selection);
166
216
static gboolean    gimp_dnd_set_pattern_data   (GtkWidget        *widget,
 
217
                                                gint              x,
 
218
                                                gint              y,
167
219
                                                GCallback         set_pattern_func,
168
220
                                                gpointer          set_pattern_data,
169
221
                                                GtkSelectionData *selection);
170
222
static gboolean    gimp_dnd_set_gradient_data  (GtkWidget        *widget,
 
223
                                                gint              x,
 
224
                                                gint              y,
171
225
                                                GCallback         set_gradient_func,
172
226
                                                gpointer          set_gradient_data,
173
227
                                                GtkSelectionData *selection);
174
228
static gboolean    gimp_dnd_set_palette_data   (GtkWidget        *widget,
 
229
                                                gint              x,
 
230
                                                gint              y,
175
231
                                                GCallback         set_palette_func,
176
232
                                                gpointer          set_palette_data,
177
233
                                                GtkSelectionData *selection);
178
234
static gboolean    gimp_dnd_set_font_data      (GtkWidget        *widget,
 
235
                                                gint              x,
 
236
                                                gint              y,
179
237
                                                GCallback         set_font_func,
180
238
                                                gpointer          set_font_data,
181
239
                                                GtkSelectionData *selection);
182
240
static gboolean    gimp_dnd_set_buffer_data    (GtkWidget        *widget,
 
241
                                                gint              x,
 
242
                                                gint              y,
183
243
                                                GCallback         set_buffer_func,
184
244
                                                gpointer          set_buffer_data,
185
245
                                                GtkSelectionData *selection);
186
246
static gboolean    gimp_dnd_set_imagefile_data (GtkWidget        *widget,
 
247
                                                gint              x,
 
248
                                                gint              y,
187
249
                                                GCallback         set_imagefile_func,
188
250
                                                gpointer          set_imagefile_data,
189
251
                                                GtkSelectionData *selection);
190
252
static gboolean    gimp_dnd_set_template_data  (GtkWidget        *widget,
 
253
                                                gint              x,
 
254
                                                gint              y,
191
255
                                                GCallback         set_template_func,
192
256
                                                gpointer          set_template_data,
193
257
                                                GtkSelectionData *selection);
194
 
static gboolean    gimp_dnd_set_tool_data      (GtkWidget        *widget,
195
 
                                                GCallback         set_tool_func,
196
 
                                                gpointer          set_tool_data,
 
258
static gboolean    gimp_dnd_set_tool_info_data (GtkWidget        *widget,
 
259
                                                gint              x,
 
260
                                                gint              y,
 
261
                                                GCallback         set_tool_info_func,
 
262
                                                gpointer          set_tool_info_data,
197
263
                                                GtkSelectionData *selection);
198
264
 
199
265
 
200
266
 
201
 
static GimpDndDataDef dnd_data_defs[] =
 
267
static const GimpDndDataDef dnd_data_defs[] =
202
268
{
203
269
  {
204
270
    { NULL, 0, -1 },
254
320
  },
255
321
 
256
322
  {
 
323
    GIMP_TARGET_XDS,
 
324
 
 
325
    "gimp-dnd-get-xds-func",
 
326
    "gimp-dnd-get-xds-data",
 
327
 
 
328
    NULL,
 
329
    NULL,
 
330
 
 
331
    gimp_dnd_get_viewable_icon,
 
332
    gimp_dnd_get_xds_data,
 
333
    NULL
 
334
  },
 
335
 
 
336
  {
257
337
    GIMP_TARGET_COLOR,
258
338
 
259
339
    "gimp-dnd-get-color-func",
268
348
  },
269
349
 
270
350
  {
271
 
    GIMP_TARGET_PNG,
272
 
 
273
 
    "gimp-dnd-get-png-func",
274
 
    "gimp-dnd-get-png-data",
275
 
 
276
 
    "gimp-dnd-set-png-func",
277
 
    "gimp-dnd-set-png-data",
278
 
 
279
 
    gimp_dnd_get_viewable_icon,
280
 
    gimp_dnd_get_stream_data,
281
 
    gimp_dnd_set_stream_data
282
 
  },
283
 
 
284
 
  {
285
351
    GIMP_TARGET_SVG,
286
352
 
287
353
    "gimp-dnd-get-svg-func",
310
376
  },
311
377
 
312
378
  {
 
379
    GIMP_TARGET_PIXBUF,
 
380
 
 
381
    "gimp-dnd-get-pixbuf-func",
 
382
    "gimp-dnd-get-pixbuf-data",
 
383
 
 
384
    "gimp-dnd-set-pixbuf-func",
 
385
    "gimp-dnd-set-pixbuf-data",
 
386
 
 
387
    gimp_dnd_get_viewable_icon,
 
388
    gimp_dnd_get_pixbuf_data,
 
389
    gimp_dnd_set_pixbuf_data
 
390
  },
 
391
 
 
392
  {
313
393
    GIMP_TARGET_IMAGE,
314
394
 
315
395
    "gimp-dnd-get-image-func",
324
404
  },
325
405
 
326
406
  {
 
407
    GIMP_TARGET_COMPONENT,
 
408
 
 
409
    "gimp-dnd-get-component-func",
 
410
    "gimp-dnd-get-component-data",
 
411
 
 
412
    "gimp-dnd-set-component-func",
 
413
    "gimp-dnd-set-component-data",
 
414
 
 
415
    gimp_dnd_get_component_icon,
 
416
    gimp_dnd_get_component_data,
 
417
    gimp_dnd_set_component_data,
 
418
  },
 
419
 
 
420
  {
327
421
    GIMP_TARGET_LAYER,
328
422
 
329
423
    "gimp-dnd-get-layer-func",
366
460
  },
367
461
 
368
462
  {
369
 
    GIMP_TARGET_COMPONENT,
370
 
 
371
 
    NULL,
372
 
    NULL,
373
 
 
374
 
    NULL,
375
 
    NULL,
376
 
 
377
 
    NULL,
378
 
    NULL,
379
 
    NULL,
380
 
  },
381
 
 
382
 
  {
383
463
    GIMP_TARGET_VECTORS,
384
464
 
385
465
    "gimp-dnd-get-vectors-func",
403
483
    "gimp-dnd-set-brush-data",
404
484
 
405
485
    gimp_dnd_get_viewable_icon,
406
 
    gimp_dnd_get_data_data,
 
486
    gimp_dnd_get_object_data,
407
487
    gimp_dnd_set_brush_data
408
488
  },
409
489
 
417
497
    "gimp-dnd-set-pattern-data",
418
498
 
419
499
    gimp_dnd_get_viewable_icon,
420
 
    gimp_dnd_get_data_data,
 
500
    gimp_dnd_get_object_data,
421
501
    gimp_dnd_set_pattern_data
422
502
  },
423
503
 
431
511
    "gimp-dnd-set-gradient-data",
432
512
 
433
513
    gimp_dnd_get_viewable_icon,
434
 
    gimp_dnd_get_data_data,
 
514
    gimp_dnd_get_object_data,
435
515
    gimp_dnd_set_gradient_data
436
516
  },
437
517
 
445
525
    "gimp-dnd-set-palette-data",
446
526
 
447
527
    gimp_dnd_get_viewable_icon,
448
 
    gimp_dnd_get_data_data,
 
528
    gimp_dnd_get_object_data,
449
529
    gimp_dnd_set_palette_data
450
530
  },
451
531
 
459
539
    "gimp-dnd-set-font-data",
460
540
 
461
541
    gimp_dnd_get_viewable_icon,
462
 
    gimp_dnd_get_data_data,
 
542
    gimp_dnd_get_object_data,
463
543
    gimp_dnd_set_font_data
464
544
  },
465
545
 
473
553
    "gimp-dnd-set-buffer-data",
474
554
 
475
555
    gimp_dnd_get_viewable_icon,
476
 
    gimp_dnd_get_data_data,
 
556
    gimp_dnd_get_object_data,
477
557
    gimp_dnd_set_buffer_data
478
558
  },
479
559
 
487
567
    "gimp-dnd-set-imagefile-data",
488
568
 
489
569
    gimp_dnd_get_viewable_icon,
490
 
    gimp_dnd_get_data_data,
 
570
    gimp_dnd_get_object_data,
491
571
    gimp_dnd_set_imagefile_data
492
572
  },
493
573
 
501
581
    "gimp-dnd-set-template-data",
502
582
 
503
583
    gimp_dnd_get_viewable_icon,
504
 
    gimp_dnd_get_data_data,
 
584
    gimp_dnd_get_object_data,
505
585
    gimp_dnd_set_template_data
506
586
  },
507
587
 
508
588
  {
509
 
    GIMP_TARGET_TOOL,
510
 
 
511
 
    "gimp-dnd-get-tool-func",
512
 
    "gimp-dnd-get-tool-data",
513
 
 
514
 
    "gimp-dnd-set-tool-func",
515
 
    "gimp-dnd-set-tool-data",
 
589
    GIMP_TARGET_TOOL_INFO,
 
590
 
 
591
    "gimp-dnd-get-tool-info-func",
 
592
    "gimp-dnd-get-tool-info-data",
 
593
 
 
594
    "gimp-dnd-set-tool-info-func",
 
595
    "gimp-dnd-set-tool-info-data",
516
596
 
517
597
    gimp_dnd_get_viewable_icon,
518
 
    gimp_dnd_get_data_data,
519
 
    gimp_dnd_set_tool_data
 
598
    gimp_dnd_get_object_data,
 
599
    gimp_dnd_set_tool_info_data
520
600
  },
521
601
 
522
602
  {
548
628
}
549
629
 
550
630
 
 
631
/**********************/
 
632
/*  helper functions  */
 
633
/**********************/
 
634
 
 
635
static void
 
636
gimp_dnd_target_list_add (GtkTargetList        *list,
 
637
                          const GtkTargetEntry *entry)
 
638
{
 
639
  GdkAtom atom = gdk_atom_intern (entry->target, FALSE);
 
640
  guint   info;
 
641
 
 
642
  if (! gtk_target_list_find (list, atom, &info) || info != entry->info)
 
643
    {
 
644
      gtk_target_list_add (list, atom, entry->flags, entry->info);
 
645
    }
 
646
}
 
647
 
 
648
 
551
649
/********************************/
552
650
/*  general data dnd functions  */
553
651
/********************************/
557
655
                          GdkDragContext *context,
558
656
                          gpointer        data)
559
657
{
560
 
  GimpDndType     data_type;
561
 
  GimpDndDataDef *dnd_data;
562
 
  GCallback       get_data_func = NULL;
563
 
  gpointer        get_data_data = NULL;
564
 
  GtkWidget      *icon_widget;
 
658
  const GimpDndDataDef *dnd_data;
 
659
  GimpDndType           data_type;
 
660
  GCallback             get_data_func = NULL;
 
661
  gpointer              get_data_data = NULL;
 
662
  GtkWidget            *icon_widget;
565
663
 
566
664
  data_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
567
665
                                                  "gimp-dnd-get-data-type"));
568
666
 
 
667
  D (g_printerr ("\ngimp_dnd_data_drag_begin (%d)\n", data_type));
 
668
 
569
669
  if (! data_type)
570
670
    return;
571
671
 
619
719
{
620
720
  GtkWidget *icon_widget;
621
721
 
 
722
  D (g_printerr ("\ngimp_dnd_data_drag_end\n"));
 
723
 
622
724
  icon_widget = g_object_get_data (G_OBJECT (widget), "gimp-dnd-data-widget");
623
725
 
624
726
  if (icon_widget)
647
749
  gpointer     get_data_data = NULL;
648
750
  GimpDndType  data_type;
649
751
 
650
 
  D (g_print ("\ngimp_dnd_data_drag_handle(%d)\n", info));
 
752
  D (g_printerr ("\ngimp_dnd_data_drag_handle(%d)\n", info));
651
753
 
652
754
  for (data_type = GIMP_DND_TYPE_NONE + 1;
653
755
       data_type <= GIMP_DND_TYPE_LAST;
654
756
       data_type++)
655
757
    {
656
 
      GimpDndDataDef *dnd_data = dnd_data_defs + data_type;
 
758
      const GimpDndDataDef *dnd_data = dnd_data_defs + data_type;
657
759
 
658
760
      if (dnd_data->target_entry.info == info)
659
761
        {
660
 
          GdkAtom atom;
661
 
 
662
 
          D (g_print ("gimp_dnd_data_drag_handle(%s)\n",
663
 
                      dnd_data->target_entry.target));
 
762
          D (g_printerr ("gimp_dnd_data_drag_handle(%s)\n",
 
763
                         dnd_data->target_entry.target));
664
764
 
665
765
          if (dnd_data->get_data_func_name)
666
766
            get_data_func = g_object_get_data (G_OBJECT (widget),
673
773
          if (! get_data_func)
674
774
            return;
675
775
 
676
 
          atom = gdk_atom_intern (dnd_data->target_entry.target, FALSE);
677
 
 
678
776
          dnd_data->get_data_func (widget,
 
777
                                   context,
679
778
                                   get_data_func,
680
779
                                   get_data_data,
681
 
                                   selection_data,
682
 
                                   atom);
 
780
                                   selection_data);
683
781
 
684
782
          return;
685
783
        }
698
796
{
699
797
  GimpDndType data_type;
700
798
 
701
 
  D (g_print ("\ngimp_dnd_data_drop_handle(%d)\n", info));
 
799
  D (g_printerr ("\ngimp_dnd_data_drop_handle(%d)\n", info));
702
800
 
703
801
  if (selection_data->length <= 0)
704
802
    {
710
808
       data_type <= GIMP_DND_TYPE_LAST;
711
809
       data_type++)
712
810
    {
713
 
      GimpDndDataDef *dnd_data = dnd_data_defs + data_type;
 
811
      const GimpDndDataDef *dnd_data = dnd_data_defs + data_type;
714
812
 
715
813
      if (dnd_data->target_entry.info == info)
716
814
        {
717
815
          GCallback set_data_func = NULL;
718
816
          gpointer  set_data_data = NULL;
719
817
 
720
 
          D (g_print ("gimp_dnd_data_drop_handle(%s)\n",
721
 
                      dnd_data->target_entry.target));
 
818
          D (g_printerr ("gimp_dnd_data_drop_handle(%s)\n",
 
819
                         dnd_data->target_entry.target));
722
820
 
723
821
          if (dnd_data->set_data_func_name)
724
822
            set_data_func = g_object_get_data (G_OBJECT (widget),
729
827
                                               dnd_data->set_data_data_name);
730
828
 
731
829
          if (set_data_func &&
732
 
              dnd_data->set_data_func (widget,
 
830
              dnd_data->set_data_func (widget, x, y,
733
831
                                       set_data_func,
734
832
                                       set_data_data,
735
833
                                       selection_data))
750
848
                          GCallback    get_data_func,
751
849
                          gpointer     get_data_data)
752
850
{
753
 
  GimpDndDataDef *dnd_data;
754
 
  GtkTargetList  *target_list;
755
 
  gboolean        drag_connected;
 
851
  const GimpDndDataDef *dnd_data;
 
852
  gboolean              drag_connected;
756
853
 
757
854
  dnd_data = dnd_data_defs + data_type;
758
855
 
759
856
  /*  set a default drag source if not already done  */
760
857
  if (! g_object_get_data (G_OBJECT (widget), "gtk-site-data"))
761
858
    gtk_drag_source_set (widget, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
762
 
                         &dnd_data->target_entry, 1,
 
859
                         NULL, 0,
763
860
                         GDK_ACTION_COPY | GDK_ACTION_MOVE);
764
861
 
765
862
  drag_connected =
768
865
 
769
866
  if (! drag_connected)
770
867
    {
771
 
      g_signal_connect (widget, "drag_begin",
 
868
      g_signal_connect (widget, "drag-begin",
772
869
                        G_CALLBACK (gimp_dnd_data_drag_begin),
773
870
                        NULL);
774
 
      g_signal_connect (widget, "drag_end",
 
871
      g_signal_connect (widget, "drag-end",
775
872
                        G_CALLBACK (gimp_dnd_data_drag_end),
776
873
                        NULL);
777
 
      g_signal_connect (widget, "drag_data_get",
 
874
      g_signal_connect (widget, "drag-data-get",
778
875
                        G_CALLBACK (gimp_dnd_data_drag_handle),
779
876
                        NULL);
780
877
 
792
889
    g_object_set_data (G_OBJECT (widget), "gimp-dnd-get-data-type",
793
890
                       GINT_TO_POINTER (data_type));
794
891
 
795
 
  target_list = gtk_drag_source_get_target_list (widget);
796
 
 
797
 
  if (target_list)
798
 
    {
799
 
      GdkAtom atom = gdk_atom_intern (dnd_data->target_entry.target, TRUE);
800
 
 
801
 
      gtk_target_list_add (target_list, atom,
802
 
                           dnd_data->target_entry.flags,
803
 
                           dnd_data->target_entry.info);
804
 
    }
805
 
  else
806
 
    {
807
 
      target_list = gtk_target_list_new (&dnd_data->target_entry, 1);
808
 
 
809
 
      gtk_drag_source_set_target_list (widget, target_list);
810
 
      gtk_target_list_unref (target_list);
 
892
  if (dnd_data->target_entry.target)
 
893
    {
 
894
      GtkTargetList *target_list;
 
895
 
 
896
      target_list = gtk_drag_source_get_target_list (widget);
 
897
 
 
898
      if (target_list)
 
899
        {
 
900
          gimp_dnd_target_list_add (target_list, &dnd_data->target_entry);
 
901
        }
 
902
      else
 
903
        {
 
904
          target_list = gtk_target_list_new (&dnd_data->target_entry, 1);
 
905
 
 
906
          gtk_drag_source_set_target_list (widget, target_list);
 
907
          gtk_target_list_unref (target_list);
 
908
        }
811
909
    }
812
910
}
813
911
 
815
913
gimp_dnd_data_source_remove (GimpDndType  data_type,
816
914
                             GtkWidget   *widget)
817
915
{
818
 
  GimpDndDataDef *dnd_data;
819
 
  GtkTargetList  *target_list;
820
 
  gboolean        drag_connected;
 
916
  const GimpDndDataDef *dnd_data;
 
917
  gboolean              drag_connected;
821
918
 
822
919
  drag_connected =
823
920
    GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
837
934
                                          "gimp-dnd-get-data-type")))
838
935
    g_object_set_data (G_OBJECT (widget), "gimp-dnd-get-data-type", NULL);
839
936
 
840
 
  target_list = gtk_drag_source_get_target_list (widget);
841
 
 
842
 
  if (target_list)
 
937
  if (dnd_data->target_entry.target)
843
938
    {
844
 
      GdkAtom atom = gdk_atom_intern (dnd_data->target_entry.target, TRUE);
845
 
 
846
 
      if (atom != GDK_NONE)
847
 
        gtk_target_list_remove (target_list, atom);
 
939
      GtkTargetList *target_list;
 
940
 
 
941
      target_list = gtk_drag_source_get_target_list (widget);
 
942
 
 
943
      if (target_list)
 
944
        {
 
945
          GdkAtom atom = gdk_atom_intern (dnd_data->target_entry.target, TRUE);
 
946
 
 
947
          if (atom != GDK_NONE)
 
948
            gtk_target_list_remove (target_list, atom);
 
949
        }
848
950
    }
849
951
}
850
952
 
854
956
                        gpointer     set_data_func,
855
957
                        gpointer     set_data_data)
856
958
{
857
 
  GimpDndDataDef *dnd_data;
858
 
  GtkTargetList  *target_list;
859
 
  gboolean        drop_connected;
 
959
  const GimpDndDataDef *dnd_data;
 
960
  gboolean              drop_connected;
860
961
 
861
962
  /*  set a default drag dest if not already done  */
862
963
  if (! g_object_get_data (G_OBJECT (widget), "gtk-drag-dest"))
868
969
 
869
970
  if (set_data_func && ! drop_connected)
870
971
    {
871
 
      g_signal_connect (widget, "drag_data_received",
 
972
      g_signal_connect (widget, "drag-data-received",
872
973
                        G_CALLBACK (gimp_dnd_data_drop_handle),
873
974
                        NULL);
874
975
 
886
987
                         set_data_data);
887
988
    }
888
989
 
889
 
  target_list = gtk_drag_dest_get_target_list (widget);
890
 
 
891
 
  if (target_list)
892
 
    {
893
 
      GdkAtom atom = gdk_atom_intern (dnd_data->target_entry.target, TRUE);
894
 
 
895
 
      gtk_target_list_add (target_list, atom,
896
 
                           dnd_data->target_entry.flags,
897
 
                           dnd_data->target_entry.info);
898
 
    }
899
 
  else
900
 
    {
901
 
      target_list = gtk_target_list_new (&dnd_data->target_entry, 1);
902
 
 
903
 
      gtk_drag_dest_set_target_list (widget, target_list);
904
 
      gtk_target_list_unref (target_list);
 
990
  if (dnd_data->target_entry.target)
 
991
    {
 
992
      GtkTargetList *target_list;
 
993
 
 
994
      target_list = gtk_drag_dest_get_target_list (widget);
 
995
 
 
996
      if (target_list)
 
997
        {
 
998
          gimp_dnd_target_list_add (target_list, &dnd_data->target_entry);
 
999
        }
 
1000
      else
 
1001
        {
 
1002
          target_list = gtk_target_list_new (&dnd_data->target_entry, 1);
 
1003
 
 
1004
          gtk_drag_dest_set_target_list (widget, target_list);
 
1005
          gtk_target_list_unref (target_list);
 
1006
        }
905
1007
    }
906
1008
}
907
1009
 
909
1011
gimp_dnd_data_dest_remove (GimpDndType  data_type,
910
1012
                           GtkWidget   *widget)
911
1013
{
912
 
  GimpDndDataDef *dnd_data;
913
 
  GtkTargetList  *target_list;
 
1014
  const GimpDndDataDef *dnd_data;
914
1015
 
915
1016
  dnd_data = dnd_data_defs + data_type;
916
1017
 
917
1018
  g_object_set_data (G_OBJECT (widget), dnd_data->set_data_func_name, NULL);
918
1019
  g_object_set_data (G_OBJECT (widget), dnd_data->set_data_data_name, NULL);
919
1020
 
920
 
  target_list = gtk_drag_dest_get_target_list (widget);
921
 
 
922
 
  if (target_list)
 
1021
  if (dnd_data->target_entry.target)
923
1022
    {
924
 
      GdkAtom atom = gdk_atom_intern (dnd_data->target_entry.target, TRUE);
925
 
 
926
 
      if (atom != GDK_NONE)
927
 
        gtk_target_list_remove (target_list, atom);
 
1023
      GtkTargetList *target_list;
 
1024
 
 
1025
      target_list = gtk_drag_dest_get_target_list (widget);
 
1026
 
 
1027
      if (target_list)
 
1028
        {
 
1029
          GdkAtom atom = gdk_atom_intern (dnd_data->target_entry.target, TRUE);
 
1030
 
 
1031
          if (atom != GDK_NONE)
 
1032
            gtk_target_list_remove (target_list, atom);
 
1033
        }
928
1034
    }
929
1035
}
930
1036
 
935
1041
 
936
1042
static void
937
1043
gimp_dnd_get_uri_list_data (GtkWidget        *widget,
 
1044
                            GdkDragContext   *context,
938
1045
                            GCallback         get_uri_list_func,
939
1046
                            gpointer          get_uri_list_data,
940
 
                            GtkSelectionData *selection,
941
 
                            GdkAtom           atom)
 
1047
                            GtkSelectionData *selection)
942
1048
{
943
1049
  GList *uri_list;
944
1050
 
947
1053
 
948
1054
  if (uri_list)
949
1055
    {
950
 
      gimp_selection_data_set_uri_list (selection, atom, uri_list);
 
1056
      gimp_selection_data_set_uri_list (selection, uri_list);
951
1057
 
952
1058
      g_list_foreach (uri_list, (GFunc) g_free, NULL);
953
1059
      g_list_free (uri_list);
956
1062
 
957
1063
static gboolean
958
1064
gimp_dnd_set_uri_list_data (GtkWidget        *widget,
 
1065
                            gint              x,
 
1066
                            gint              y,
959
1067
                            GCallback         set_uri_list_func,
960
1068
                            gpointer          set_uri_list_data,
961
1069
                            GtkSelectionData *selection)
965
1073
  if (! uri_list)
966
1074
    return FALSE;
967
1075
 
968
 
  (* (GimpDndDropUriListFunc) set_uri_list_func) (widget, uri_list,
 
1076
  (* (GimpDndDropUriListFunc) set_uri_list_func) (widget, x, y, uri_list,
969
1077
                                                  set_uri_list_data);
970
1078
 
971
1079
  g_list_foreach (uri_list, (GFunc) g_free, NULL);
1032
1140
}
1033
1141
 
1034
1142
 
 
1143
/******************************/
 
1144
/* Direct Save Protocol (XDS) */
 
1145
/******************************/
 
1146
 
 
1147
static void
 
1148
gimp_dnd_get_xds_data (GtkWidget        *widget,
 
1149
                       GdkDragContext   *context,
 
1150
                       GCallback         get_image_func,
 
1151
                       gpointer          get_image_data,
 
1152
                       GtkSelectionData *selection)
 
1153
{
 
1154
  GimpImage   *image;
 
1155
  GimpContext *gimp_context;
 
1156
 
 
1157
  image = (GimpImage *)
 
1158
    (* (GimpDndDragViewableFunc) get_image_func) (widget, &gimp_context,
 
1159
                                                  get_image_data);
 
1160
 
 
1161
  if (image)
 
1162
    gimp_dnd_xds_save_image (context, image, selection);
 
1163
}
 
1164
 
 
1165
static void
 
1166
gimp_dnd_xds_drag_begin (GtkWidget      *widget,
 
1167
                         GdkDragContext *context)
 
1168
{
 
1169
  const GimpDndDataDef *dnd_data = dnd_data_defs + GIMP_DND_TYPE_XDS;
 
1170
  GCallback             get_data_func;
 
1171
  gpointer              get_data_data;
 
1172
 
 
1173
  get_data_func = g_object_get_data (G_OBJECT (widget),
 
1174
                                     dnd_data->get_data_func_name);
 
1175
  get_data_data = g_object_get_data (G_OBJECT (widget),
 
1176
                                     dnd_data->get_data_data_name);
 
1177
 
 
1178
  if (get_data_func)
 
1179
    {
 
1180
      GimpImage   *image;
 
1181
      GimpContext *gimp_context;
 
1182
 
 
1183
      image = (GimpImage *)
 
1184
        (* (GimpDndDragViewableFunc) get_data_func) (widget, &gimp_context,
 
1185
                                                     get_data_data);
 
1186
 
 
1187
      gimp_dnd_xds_source_set (context, image);
 
1188
    }
 
1189
}
 
1190
 
 
1191
static void
 
1192
gimp_dnd_xds_drag_end (GtkWidget      *widget,
 
1193
                       GdkDragContext *context)
 
1194
{
 
1195
  gimp_dnd_xds_source_set (context, NULL);
 
1196
}
 
1197
 
 
1198
void
 
1199
gimp_dnd_xds_source_add (GtkWidget               *widget,
 
1200
                         GimpDndDragViewableFunc  get_image_func,
 
1201
                         gpointer                 data)
 
1202
{
 
1203
  gulong handler;
 
1204
 
 
1205
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1206
 
 
1207
  gimp_dnd_data_source_add (GIMP_DND_TYPE_XDS, widget,
 
1208
                            G_CALLBACK (get_image_func),
 
1209
                            data);
 
1210
 
 
1211
  handler = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
 
1212
                                                 "gimp-dnd-xds-drag-begin"));
 
1213
 
 
1214
  if (! handler)
 
1215
    {
 
1216
      handler = g_signal_connect (widget, "drag-begin",
 
1217
                                  G_CALLBACK (gimp_dnd_xds_drag_begin),
 
1218
                                  NULL);
 
1219
      g_object_set_data (G_OBJECT (widget), "gimp-dnd-xds-drag-begin",
 
1220
                         GUINT_TO_POINTER (handler));
 
1221
    }
 
1222
 
 
1223
  handler = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
 
1224
                                                 "gimp-dnd-xds-drag-end"));
 
1225
 
 
1226
  if (! handler)
 
1227
    {
 
1228
      handler = g_signal_connect (widget, "drag-end",
 
1229
                                  G_CALLBACK (gimp_dnd_xds_drag_end),
 
1230
                                  NULL);
 
1231
      g_object_set_data (G_OBJECT (widget), "gimp-dnd-xds-drag-end",
 
1232
                         GUINT_TO_POINTER (handler));
 
1233
    }
 
1234
}
 
1235
 
 
1236
void
 
1237
gimp_dnd_xds_source_remove (GtkWidget *widget)
 
1238
{
 
1239
  gulong handler;
 
1240
 
 
1241
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1242
 
 
1243
  handler = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
 
1244
                                                 "gimp-dnd-xds-drag-begin"));
 
1245
  if (handler)
 
1246
    {
 
1247
      g_signal_handler_disconnect (widget, handler);
 
1248
      g_object_set_data (G_OBJECT (widget), "gimp-dnd-xds-drag-begin", NULL);
 
1249
    }
 
1250
 
 
1251
  handler = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
 
1252
                                                 "gimp-dnd-xds-drag-end"));
 
1253
  if (handler)
 
1254
    {
 
1255
      g_signal_handler_disconnect (widget, handler);
 
1256
      g_object_set_data (G_OBJECT (widget), "gimp-dnd-xds-drag-end", NULL);
 
1257
    }
 
1258
 
 
1259
  gimp_dnd_data_source_remove (GIMP_DND_TYPE_XDS, widget);
 
1260
}
 
1261
 
 
1262
 
1035
1263
/*************************/
1036
1264
/*  color dnd functions  */
1037
1265
/*************************/
1046
1274
 
1047
1275
  (* (GimpDndDragColorFunc) get_color_func) (widget, &color, get_color_data);
1048
1276
 
1049
 
  color_area = gimp_color_area_new (&color, TRUE, 0);
1050
 
  gtk_widget_set_size_request (color_area, DRAG_PREVIEW_SIZE, DRAG_PREVIEW_SIZE);
 
1277
  color_area = gimp_color_area_new (&color, GIMP_COLOR_AREA_SMALL_CHECKS, 0);
 
1278
  gtk_widget_set_size_request (color_area,
 
1279
                               DRAG_PREVIEW_SIZE, DRAG_PREVIEW_SIZE);
1051
1280
 
1052
1281
  return color_area;
1053
1282
}
1054
1283
 
1055
1284
static void
1056
1285
gimp_dnd_get_color_data (GtkWidget        *widget,
 
1286
                         GdkDragContext   *context,
1057
1287
                         GCallback         get_color_func,
1058
1288
                         gpointer          get_color_data,
1059
 
                         GtkSelectionData *selection,
1060
 
                         GdkAtom           atom)
 
1289
                         GtkSelectionData *selection)
1061
1290
{
1062
1291
  GimpRGB color;
1063
1292
 
1064
1293
  (* (GimpDndDragColorFunc) get_color_func) (widget, &color, get_color_data);
1065
1294
 
1066
 
  gimp_selection_data_set_color (selection, atom, &color);
 
1295
  gimp_selection_data_set_color (selection, &color);
1067
1296
}
1068
1297
 
1069
1298
static gboolean
1070
1299
gimp_dnd_set_color_data (GtkWidget        *widget,
 
1300
                         gint              x,
 
1301
                         gint              y,
1071
1302
                         GCallback         set_color_func,
1072
1303
                         gpointer          set_color_data,
1073
1304
                         GtkSelectionData *selection)
1077
1308
  if (! gimp_selection_data_get_color (selection, &color))
1078
1309
    return FALSE;
1079
1310
 
1080
 
  (* (GimpDndDropColorFunc) set_color_func) (widget, &color,
 
1311
  (* (GimpDndDropColorFunc) set_color_func) (widget, x, y, &color,
1081
1312
                                             set_color_data);
1082
1313
 
1083
1314
  return TRUE;
1130
1361
 
1131
1362
static void
1132
1363
gimp_dnd_get_stream_data (GtkWidget        *widget,
 
1364
                          GdkDragContext   *context,
1133
1365
                          GCallback         get_stream_func,
1134
1366
                          gpointer          get_stream_data,
1135
 
                          GtkSelectionData *selection,
1136
 
                          GdkAtom           atom)
 
1367
                          GtkSelectionData *selection)
1137
1368
{
1138
1369
  guchar *stream;
1139
1370
  gsize   stream_length;
1143
1374
 
1144
1375
  if (stream)
1145
1376
    {
1146
 
      gimp_selection_data_set_stream (selection, atom, stream, stream_length);
 
1377
      gimp_selection_data_set_stream (selection, stream, stream_length);
1147
1378
      g_free (stream);
1148
1379
    }
1149
1380
}
1150
1381
 
1151
1382
static gboolean
1152
1383
gimp_dnd_set_stream_data (GtkWidget        *widget,
 
1384
                          gint              x,
 
1385
                          gint              y,
1153
1386
                          GCallback         set_stream_func,
1154
1387
                          gpointer          set_stream_data,
1155
1388
                          GtkSelectionData *selection)
1162
1395
  if (! stream)
1163
1396
    return FALSE;
1164
1397
 
1165
 
  (* (GimpDndDropStreamFunc) set_stream_func) (widget,
 
1398
  (* (GimpDndDropStreamFunc) set_stream_func) (widget, x, y,
1166
1399
                                               stream, stream_length,
1167
1400
                                               set_stream_data);
1168
1401
 
1218
1451
}
1219
1452
 
1220
1453
 
 
1454
/**************************/
 
1455
/*  pixbuf dnd functions  */
 
1456
/**************************/
 
1457
 
 
1458
static void
 
1459
gimp_dnd_get_pixbuf_data (GtkWidget        *widget,
 
1460
                          GdkDragContext   *context,
 
1461
                          GCallback         get_pixbuf_func,
 
1462
                          gpointer          get_pixbuf_data,
 
1463
                          GtkSelectionData *selection)
 
1464
{
 
1465
  GdkPixbuf *pixbuf;
 
1466
 
 
1467
  pixbuf = (* (GimpDndDragPixbufFunc) get_pixbuf_func) (widget,
 
1468
                                                        get_pixbuf_data);
 
1469
 
 
1470
  if (pixbuf)
 
1471
    {
 
1472
      gimp_set_busy (the_dnd_gimp);
 
1473
 
 
1474
      gtk_selection_data_set_pixbuf (selection, pixbuf);
 
1475
      g_object_unref (pixbuf);
 
1476
 
 
1477
      gimp_unset_busy (the_dnd_gimp);
 
1478
    }
 
1479
}
 
1480
 
 
1481
static gboolean
 
1482
gimp_dnd_set_pixbuf_data (GtkWidget        *widget,
 
1483
                          gint              x,
 
1484
                          gint              y,
 
1485
                          GCallback         set_pixbuf_func,
 
1486
                          gpointer          set_pixbuf_data,
 
1487
                          GtkSelectionData *selection)
 
1488
{
 
1489
  GdkPixbuf *pixbuf;
 
1490
 
 
1491
  gimp_set_busy (the_dnd_gimp);
 
1492
 
 
1493
  pixbuf = gtk_selection_data_get_pixbuf (selection);
 
1494
 
 
1495
  gimp_unset_busy (the_dnd_gimp);
 
1496
 
 
1497
  if (! pixbuf)
 
1498
    return FALSE;
 
1499
 
 
1500
  (* (GimpDndDropPixbufFunc) set_pixbuf_func) (widget, x, y,
 
1501
                                               pixbuf,
 
1502
                                               set_pixbuf_data);
 
1503
 
 
1504
  g_object_unref (pixbuf);
 
1505
 
 
1506
  return TRUE;
 
1507
}
 
1508
 
 
1509
void
 
1510
gimp_dnd_pixbuf_source_add (GtkWidget             *widget,
 
1511
                            GimpDndDragPixbufFunc  get_pixbuf_func,
 
1512
                            gpointer               data)
 
1513
{
 
1514
  GtkTargetList *target_list;
 
1515
 
 
1516
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1517
 
 
1518
  gimp_dnd_data_source_add (GIMP_DND_TYPE_PIXBUF, widget,
 
1519
                            G_CALLBACK (get_pixbuf_func),
 
1520
                            data);
 
1521
 
 
1522
  target_list = gtk_drag_source_get_target_list (widget);
 
1523
 
 
1524
  if (target_list)
 
1525
    gtk_target_list_ref (target_list);
 
1526
  else
 
1527
    target_list = gtk_target_list_new (NULL, 0);
 
1528
 
 
1529
  gimp_pixbuf_targets_add (target_list, GIMP_DND_TYPE_PIXBUF, TRUE);
 
1530
 
 
1531
  gtk_drag_source_set_target_list (widget, target_list);
 
1532
  gtk_target_list_unref (target_list);
 
1533
}
 
1534
 
 
1535
void
 
1536
gimp_dnd_pixbuf_source_remove (GtkWidget *widget)
 
1537
{
 
1538
  GtkTargetList *target_list;
 
1539
 
 
1540
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1541
 
 
1542
  gimp_dnd_data_source_remove (GIMP_DND_TYPE_PIXBUF, widget);
 
1543
 
 
1544
  target_list = gtk_drag_source_get_target_list (widget);
 
1545
 
 
1546
  if (target_list)
 
1547
    gimp_pixbuf_targets_remove (target_list);
 
1548
}
 
1549
 
 
1550
void
 
1551
gimp_dnd_pixbuf_dest_add (GtkWidget              *widget,
 
1552
                          GimpDndDropPixbufFunc   set_pixbuf_func,
 
1553
                          gpointer                data)
 
1554
{
 
1555
  GtkTargetList *target_list;
 
1556
 
 
1557
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1558
 
 
1559
  gimp_dnd_data_dest_add (GIMP_DND_TYPE_PIXBUF, widget,
 
1560
                          G_CALLBACK (set_pixbuf_func),
 
1561
                          data);
 
1562
 
 
1563
  target_list = gtk_drag_dest_get_target_list (widget);
 
1564
 
 
1565
  if (target_list)
 
1566
    gtk_target_list_ref (target_list);
 
1567
  else
 
1568
    target_list = gtk_target_list_new (NULL, 0);
 
1569
 
 
1570
  gimp_pixbuf_targets_add (target_list, GIMP_DND_TYPE_PIXBUF, FALSE);
 
1571
 
 
1572
  gtk_drag_dest_set_target_list (widget, target_list);
 
1573
  gtk_target_list_unref (target_list);
 
1574
}
 
1575
 
 
1576
void
 
1577
gimp_dnd_pixbuf_dest_remove (GtkWidget *widget)
 
1578
{
 
1579
  GtkTargetList *target_list;
 
1580
 
 
1581
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1582
 
 
1583
  gimp_dnd_data_dest_remove (GIMP_DND_TYPE_PIXBUF, widget);
 
1584
 
 
1585
  target_list = gtk_drag_dest_get_target_list (widget);
 
1586
 
 
1587
  if (target_list)
 
1588
    gimp_pixbuf_targets_remove (target_list);
 
1589
}
 
1590
 
 
1591
 
 
1592
/*****************************/
 
1593
/*  component dnd functions  */
 
1594
/*****************************/
 
1595
 
 
1596
static GtkWidget *
 
1597
gimp_dnd_get_component_icon (GtkWidget *widget,
 
1598
                             GCallback  get_comp_func,
 
1599
                             gpointer   get_comp_data)
 
1600
{
 
1601
  GtkWidget       *view;
 
1602
  GimpImage       *image;
 
1603
  GimpContext     *context;
 
1604
  GimpChannelType  channel;
 
1605
 
 
1606
  image = (* (GimpDndDragComponentFunc) get_comp_func) (widget, &context,
 
1607
                                                        &channel,
 
1608
                                                        get_comp_data);
 
1609
 
 
1610
  if (! image)
 
1611
    return NULL;
 
1612
 
 
1613
  view = gimp_view_new (context, GIMP_VIEWABLE (image),
 
1614
                        DRAG_PREVIEW_SIZE, 0, TRUE);
 
1615
 
 
1616
  GIMP_VIEW_RENDERER_IMAGE (GIMP_VIEW (view)->renderer)->channel = channel;
 
1617
 
 
1618
  return view;
 
1619
}
 
1620
 
 
1621
static void
 
1622
gimp_dnd_get_component_data (GtkWidget        *widget,
 
1623
                             GdkDragContext   *context,
 
1624
                             GCallback         get_comp_func,
 
1625
                             gpointer          get_comp_data,
 
1626
                             GtkSelectionData *selection)
 
1627
{
 
1628
  GimpImage       *image;
 
1629
  GimpContext     *gimp_context;
 
1630
  GimpChannelType  channel = 0;
 
1631
 
 
1632
  image = (* (GimpDndDragComponentFunc) get_comp_func) (widget, &gimp_context,
 
1633
                                                        &channel,
 
1634
                                                        get_comp_data);
 
1635
 
 
1636
  if (image)
 
1637
    gimp_selection_data_set_component (selection, image, channel);
 
1638
}
 
1639
 
 
1640
static gboolean
 
1641
gimp_dnd_set_component_data (GtkWidget        *widget,
 
1642
                             gint              x,
 
1643
                             gint              y,
 
1644
                             GCallback         set_comp_func,
 
1645
                             gpointer          set_comp_data,
 
1646
                             GtkSelectionData *selection)
 
1647
{
 
1648
  GimpImage       *image;
 
1649
  GimpChannelType  channel = 0;
 
1650
 
 
1651
  image = gimp_selection_data_get_component (selection, the_dnd_gimp,
 
1652
                                             &channel);
 
1653
 
 
1654
  if (! image)
 
1655
    return FALSE;
 
1656
 
 
1657
  (* (GimpDndDropComponentFunc) set_comp_func) (widget, x, y,
 
1658
                                                image, channel,
 
1659
                                                set_comp_data);
 
1660
 
 
1661
  return TRUE;
 
1662
}
 
1663
 
 
1664
void
 
1665
gimp_dnd_component_source_add (GtkWidget                *widget,
 
1666
                               GimpDndDragComponentFunc  get_comp_func,
 
1667
                               gpointer                  data)
 
1668
{
 
1669
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1670
 
 
1671
  gimp_dnd_data_source_add (GIMP_DND_TYPE_COMPONENT, widget,
 
1672
                            G_CALLBACK (get_comp_func),
 
1673
                            data);
 
1674
}
 
1675
 
 
1676
void
 
1677
gimp_dnd_component_source_remove (GtkWidget *widget)
 
1678
{
 
1679
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1680
 
 
1681
  gimp_dnd_data_source_remove (GIMP_DND_TYPE_COMPONENT, widget);
 
1682
}
 
1683
 
 
1684
void
 
1685
gimp_dnd_component_dest_add (GtkWidget                 *widget,
 
1686
                             GimpDndDropComponentFunc   set_comp_func,
 
1687
                             gpointer                   data)
 
1688
{
 
1689
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1690
 
 
1691
  gimp_dnd_data_dest_add (GIMP_DND_TYPE_COMPONENT, widget,
 
1692
                          G_CALLBACK (set_comp_func),
 
1693
                          data);
 
1694
}
 
1695
 
 
1696
void
 
1697
gimp_dnd_component_dest_remove (GtkWidget *widget)
 
1698
{
 
1699
  g_return_if_fail (GTK_IS_WIDGET (widget));
 
1700
 
 
1701
  gimp_dnd_data_dest_remove (GIMP_DND_TYPE_COMPONENT, widget);
 
1702
}
 
1703
 
 
1704
 
1221
1705
/*******************************************/
1222
1706
/*  GimpViewable (by GType) dnd functions  */
1223
1707
/*******************************************/
1227
1711
                            GCallback  get_viewable_func,
1228
1712
                            gpointer   get_viewable_data)
1229
1713
{
 
1714
  GimpViewable *viewable;
 
1715
  GimpContext  *context;
1230
1716
  GtkWidget    *view;
1231
 
  GimpViewable *viewable;
 
1717
  gchar        *desc;
1232
1718
 
1233
 
  viewable = (* (GimpDndDragViewableFunc) get_viewable_func) (widget,
 
1719
  viewable = (* (GimpDndDragViewableFunc) get_viewable_func) (widget, &context,
1234
1720
                                                              get_viewable_data);
1235
1721
 
1236
1722
  if (! viewable)
1237
1723
    return NULL;
1238
1724
 
1239
 
  view = gimp_view_new (viewable, DRAG_PREVIEW_SIZE, 0, TRUE);
 
1725
  view = gimp_view_new (context, viewable,
 
1726
                        DRAG_PREVIEW_SIZE, 0, TRUE);
 
1727
 
 
1728
  desc = gimp_viewable_get_description (viewable, NULL);
 
1729
 
 
1730
  if (desc)
 
1731
    {
 
1732
      GtkWidget *hbox;
 
1733
      GtkWidget *label;
 
1734
 
 
1735
      hbox = gtk_hbox_new (FALSE, 3);
 
1736
      gtk_container_set_border_width (GTK_CONTAINER (hbox), 3);
 
1737
      gtk_box_pack_start (GTK_BOX (hbox), view, FALSE, FALSE, 0);
 
1738
      gtk_widget_show (view);
 
1739
 
 
1740
      label = g_object_new (GTK_TYPE_LABEL,
 
1741
                            "label",           desc,
 
1742
                            "xpad",            3,
 
1743
                            "xalign",          0.0,
 
1744
                            "yalign",          0.5,
 
1745
                            "max-width-chars", 30,
 
1746
                            "ellipsize",       PANGO_ELLIPSIZE_END,
 
1747
                            NULL);
 
1748
 
 
1749
      g_free (desc);
 
1750
 
 
1751
      gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
 
1752
      gtk_widget_show (label);
 
1753
 
 
1754
      return hbox;
 
1755
    }
1240
1756
 
1241
1757
  return view;
1242
1758
}
1300
1816
    }
1301
1817
  else if (g_type_is_a (type, GIMP_TYPE_TOOL_INFO))
1302
1818
    {
1303
 
      dnd_type = GIMP_DND_TYPE_TOOL;
 
1819
      dnd_type = GIMP_DND_TYPE_TOOL_INFO;
1304
1820
    }
1305
1821
 
1306
1822
  return dnd_type;
1434
1950
GimpViewable *
1435
1951
gimp_dnd_get_drag_data (GtkWidget *widget)
1436
1952
{
 
1953
  const GimpDndDataDef    *dnd_data;
1437
1954
  GimpDndType              data_type;
1438
 
  GimpDndDataDef          *dnd_data;
1439
1955
  GimpDndDragViewableFunc  get_data_func = NULL;
1440
1956
  gpointer                 get_data_data = NULL;
 
1957
  GimpContext             *context;
1441
1958
 
1442
1959
  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1443
1960
 
1460
1977
  if (! get_data_func)
1461
1978
    return NULL;
1462
1979
 
1463
 
  return (GimpViewable *) (* get_data_func) (widget, get_data_data);
 
1980
  return (GimpViewable *) (* get_data_func) (widget, &context, get_data_data);
1464
1981
 
1465
1982
}
1466
1983
 
1467
1984
 
1468
 
/*************************/
1469
 
/*  image dnd functions  */
1470
 
/*************************/
 
1985
/*****************************/
 
1986
/*  GimpImage dnd functions  */
 
1987
/*****************************/
1471
1988
 
1472
1989
static void
1473
1990
gimp_dnd_get_image_data (GtkWidget        *widget,
 
1991
                         GdkDragContext   *context,
1474
1992
                         GCallback         get_image_func,
1475
1993
                         gpointer          get_image_data,
1476
 
                         GtkSelectionData *selection,
1477
 
                         GdkAtom           atom)
 
1994
                         GtkSelectionData *selection)
1478
1995
{
1479
 
  GimpImage *gimage;
1480
 
 
1481
 
  gimage = (GimpImage *)
1482
 
    (* (GimpDndDragViewableFunc) get_image_func) (widget, get_image_data);
1483
 
 
1484
 
  if (gimage)
1485
 
    gimp_selection_data_set_image (selection, atom, gimage);
 
1996
  GimpImage   *image;
 
1997
  GimpContext *gimp_context;
 
1998
 
 
1999
  image = (GimpImage *)
 
2000
    (* (GimpDndDragViewableFunc) get_image_func) (widget, &gimp_context,
 
2001
                                                  get_image_data);
 
2002
 
 
2003
  if (image)
 
2004
    gimp_selection_data_set_image (selection, image);
1486
2005
}
1487
2006
 
1488
2007
static gboolean
1489
2008
gimp_dnd_set_image_data (GtkWidget        *widget,
 
2009
                         gint              x,
 
2010
                         gint              y,
1490
2011
                         GCallback         set_image_func,
1491
2012
                         gpointer          set_image_data,
1492
2013
                         GtkSelectionData *selection)
1493
2014
{
1494
 
  GimpImage *gimage = gimp_selection_data_get_image (selection, the_dnd_gimp);
 
2015
  GimpImage *image = gimp_selection_data_get_image (selection, the_dnd_gimp);
1495
2016
 
1496
 
  if (! gimage)
 
2017
  if (! image)
1497
2018
    return FALSE;
1498
2019
 
1499
 
  (* (GimpDndDropViewableFunc) set_image_func) (widget,
1500
 
                                                GIMP_VIEWABLE (gimage),
 
2020
  (* (GimpDndDropViewableFunc) set_image_func) (widget, x, y,
 
2021
                                                GIMP_VIEWABLE (image),
1501
2022
                                                set_image_data);
1502
2023
 
1503
2024
  return TRUE;
1504
2025
}
1505
2026
 
1506
2027
 
1507
 
/************************/
1508
 
/*  item dnd functions  */
1509
 
/************************/
 
2028
/****************************/
 
2029
/*  GimpItem dnd functions  */
 
2030
/****************************/
1510
2031
 
1511
2032
static void
1512
2033
gimp_dnd_get_item_data (GtkWidget        *widget,
 
2034
                        GdkDragContext   *context,
1513
2035
                        GCallback         get_item_func,
1514
2036
                        gpointer          get_item_data,
1515
 
                        GtkSelectionData *selection,
1516
 
                        GdkAtom           atom)
 
2037
                        GtkSelectionData *selection)
1517
2038
{
1518
 
  GimpItem *item;
 
2039
  GimpItem    *item;
 
2040
  GimpContext *gimp_context;
1519
2041
 
1520
2042
  item = (GimpItem *)
1521
 
    (* (GimpDndDragViewableFunc) get_item_func) (widget, get_item_data);
 
2043
    (* (GimpDndDragViewableFunc) get_item_func) (widget, &gimp_context,
 
2044
                                                 get_item_data);
1522
2045
 
1523
2046
  if (item)
1524
 
    gimp_selection_data_set_item (selection, atom, item);
 
2047
    gimp_selection_data_set_item (selection, item);
1525
2048
}
1526
2049
 
1527
2050
static gboolean
1528
2051
gimp_dnd_set_item_data (GtkWidget        *widget,
 
2052
                        gint              x,
 
2053
                        gint              y,
1529
2054
                        GCallback         set_item_func,
1530
2055
                        gpointer          set_item_data,
1531
2056
                        GtkSelectionData *selection)
1535
2060
  if (! item)
1536
2061
    return FALSE;
1537
2062
 
1538
 
  (* (GimpDndDropViewableFunc) set_item_func) (widget,
 
2063
  (* (GimpDndDropViewableFunc) set_item_func) (widget, x, y,
1539
2064
                                               GIMP_VIEWABLE (item),
1540
2065
                                               set_item_data);
1541
2066
 
1543
2068
}
1544
2069
 
1545
2070
 
1546
 
/****************************/
1547
 
/*  GimpData dnd functions  */
1548
 
/****************************/
 
2071
/******************************/
 
2072
/*  GimpObject dnd functions  */
 
2073
/******************************/
1549
2074
 
1550
2075
static void
1551
 
gimp_dnd_get_data_data (GtkWidget        *widget,
1552
 
                        GCallback         get_data_func,
1553
 
                        gpointer          get_data_data,
1554
 
                        GtkSelectionData *selection,
1555
 
                        GdkAtom           atom)
 
2076
gimp_dnd_get_object_data (GtkWidget        *widget,
 
2077
                          GdkDragContext   *context,
 
2078
                          GCallback         get_object_func,
 
2079
                          gpointer          get_object_data,
 
2080
                          GtkSelectionData *selection)
1556
2081
{
1557
 
  GimpData *data;
1558
 
 
1559
 
  data = (GimpData *)
1560
 
    (* (GimpDndDragViewableFunc) get_data_func) (widget, get_data_data);
1561
 
 
1562
 
  if (data)
1563
 
    gimp_selection_data_set_viewable (selection, atom, GIMP_VIEWABLE (data));
 
2082
  GimpObject  *object;
 
2083
  GimpContext *gimp_context;
 
2084
 
 
2085
  object = (GimpObject *)
 
2086
    (* (GimpDndDragViewableFunc) get_object_func) (widget, &gimp_context,
 
2087
                                                   get_object_data);
 
2088
 
 
2089
  if (GIMP_IS_OBJECT (object))
 
2090
    gimp_selection_data_set_object (selection, object);
1564
2091
}
1565
2092
 
1566
2093
 
1567
 
/*************************/
1568
 
/*  brush dnd functions  */
1569
 
/*************************/
 
2094
/*****************************/
 
2095
/*  GimpBrush dnd functions  */
 
2096
/*****************************/
1570
2097
 
1571
2098
static gboolean
1572
2099
gimp_dnd_set_brush_data (GtkWidget        *widget,
 
2100
                         gint              x,
 
2101
                         gint              y,
1573
2102
                         GCallback         set_brush_func,
1574
2103
                         gpointer          set_brush_data,
1575
2104
                         GtkSelectionData *selection)
1579
2108
  if (! brush)
1580
2109
    return FALSE;
1581
2110
 
1582
 
  (* (GimpDndDropViewableFunc) set_brush_func) (widget,
 
2111
  (* (GimpDndDropViewableFunc) set_brush_func) (widget, x, y,
1583
2112
                                                GIMP_VIEWABLE (brush),
1584
2113
                                                set_brush_data);
1585
2114
 
1587
2116
}
1588
2117
 
1589
2118
 
1590
 
/***************************/
1591
 
/*  pattern dnd functions  */
1592
 
/***************************/
 
2119
/*******************************/
 
2120
/*  GimpPattern dnd functions  */
 
2121
/*******************************/
1593
2122
 
1594
2123
static gboolean
1595
2124
gimp_dnd_set_pattern_data (GtkWidget        *widget,
 
2125
                           gint              x,
 
2126
                           gint              y,
1596
2127
                           GCallback         set_pattern_func,
1597
2128
                           gpointer          set_pattern_data,
1598
2129
                           GtkSelectionData *selection)
1603
2134
  if (! pattern)
1604
2135
    return FALSE;
1605
2136
 
1606
 
  (* (GimpDndDropViewableFunc) set_pattern_func) (widget,
 
2137
  (* (GimpDndDropViewableFunc) set_pattern_func) (widget, x, y,
1607
2138
                                                  GIMP_VIEWABLE (pattern),
1608
2139
                                                  set_pattern_data);
1609
2140
 
1611
2142
}
1612
2143
 
1613
2144
 
1614
 
/****************************/
1615
 
/*  gradient dnd functions  */
1616
 
/****************************/
 
2145
/********************************/
 
2146
/*  GimpGradient dnd functions  */
 
2147
/********************************/
1617
2148
 
1618
2149
static gboolean
1619
2150
gimp_dnd_set_gradient_data (GtkWidget        *widget,
 
2151
                            gint              x,
 
2152
                            gint              y,
1620
2153
                            GCallback         set_gradient_func,
1621
2154
                            gpointer          set_gradient_data,
1622
2155
                            GtkSelectionData *selection)
1627
2160
  if (! gradient)
1628
2161
    return FALSE;
1629
2162
 
1630
 
  (* (GimpDndDropViewableFunc) set_gradient_func) (widget,
 
2163
  (* (GimpDndDropViewableFunc) set_gradient_func) (widget, x, y,
1631
2164
                                                   GIMP_VIEWABLE (gradient),
1632
2165
                                                   set_gradient_data);
1633
2166
 
1635
2168
}
1636
2169
 
1637
2170
 
1638
 
/***************************/
1639
 
/*  palette dnd functions  */
1640
 
/***************************/
 
2171
/*******************************/
 
2172
/*  GimpPalette dnd functions  */
 
2173
/*******************************/
1641
2174
 
1642
2175
static gboolean
1643
2176
gimp_dnd_set_palette_data (GtkWidget        *widget,
 
2177
                           gint              x,
 
2178
                           gint              y,
1644
2179
                           GCallback         set_palette_func,
1645
2180
                           gpointer          set_palette_data,
1646
2181
                           GtkSelectionData *selection)
1651
2186
  if (! palette)
1652
2187
    return FALSE;
1653
2188
 
1654
 
  (* (GimpDndDropViewableFunc) set_palette_func) (widget,
 
2189
  (* (GimpDndDropViewableFunc) set_palette_func) (widget, x, y,
1655
2190
                                                  GIMP_VIEWABLE (palette),
1656
2191
                                                  set_palette_data);
1657
2192
 
1659
2194
}
1660
2195
 
1661
2196
 
1662
 
/************************/
1663
 
/*  font dnd functions  */
1664
 
/************************/
 
2197
/****************************/
 
2198
/*  GimpFont dnd functions  */
 
2199
/****************************/
1665
2200
 
1666
2201
static gboolean
1667
2202
gimp_dnd_set_font_data (GtkWidget        *widget,
 
2203
                        gint              x,
 
2204
                        gint              y,
1668
2205
                        GCallback         set_font_func,
1669
2206
                        gpointer          set_font_data,
1670
2207
                        GtkSelectionData *selection)
1674
2211
  if (! font)
1675
2212
    return FALSE;
1676
2213
 
1677
 
  (* (GimpDndDropViewableFunc) set_font_func) (widget,
 
2214
  (* (GimpDndDropViewableFunc) set_font_func) (widget, x, y,
1678
2215
                                               GIMP_VIEWABLE (font),
1679
2216
                                               set_font_data);
1680
2217
 
1682
2219
}
1683
2220
 
1684
2221
 
1685
 
/**************************/
1686
 
/*  buffer dnd functions  */
1687
 
/**************************/
 
2222
/******************************/
 
2223
/*  GimpBuffer dnd functions  */
 
2224
/******************************/
1688
2225
 
1689
2226
static gboolean
1690
2227
gimp_dnd_set_buffer_data (GtkWidget        *widget,
 
2228
                          gint              x,
 
2229
                          gint              y,
1691
2230
                          GCallback         set_buffer_func,
1692
2231
                          gpointer          set_buffer_data,
1693
2232
                          GtkSelectionData *selection)
1697
2236
  if (! buffer)
1698
2237
    return FALSE;
1699
2238
 
1700
 
  (* (GimpDndDropViewableFunc) set_buffer_func) (widget,
 
2239
  (* (GimpDndDropViewableFunc) set_buffer_func) (widget, x, y,
1701
2240
                                                 GIMP_VIEWABLE (buffer),
1702
2241
                                                 set_buffer_data);
1703
2242
 
1705
2244
}
1706
2245
 
1707
2246
 
1708
 
/*****************************/
1709
 
/*  imagefile dnd functions  */
1710
 
/*****************************/
 
2247
/*********************************/
 
2248
/*  GimpImagefile dnd functions  */
 
2249
/*********************************/
1711
2250
 
1712
2251
static gboolean
1713
2252
gimp_dnd_set_imagefile_data (GtkWidget        *widget,
 
2253
                             gint              x,
 
2254
                             gint              y,
1714
2255
                             GCallback         set_imagefile_func,
1715
2256
                             gpointer          set_imagefile_data,
1716
2257
                             GtkSelectionData *selection)
1721
2262
  if (! imagefile)
1722
2263
    return FALSE;
1723
2264
 
1724
 
  (* (GimpDndDropViewableFunc) set_imagefile_func) (widget,
 
2265
  (* (GimpDndDropViewableFunc) set_imagefile_func) (widget, x, y,
1725
2266
                                                    GIMP_VIEWABLE (imagefile),
1726
2267
                                                    set_imagefile_data);
1727
2268
 
1729
2270
}
1730
2271
 
1731
2272
 
1732
 
/*****************************/
1733
 
/*  template dnd functions  */
1734
 
/*****************************/
 
2273
/********************************/
 
2274
/*  GimpTemplate dnd functions  */
 
2275
/********************************/
1735
2276
 
1736
2277
static gboolean
1737
2278
gimp_dnd_set_template_data (GtkWidget        *widget,
 
2279
                            gint              x,
 
2280
                            gint              y,
1738
2281
                            GCallback         set_template_func,
1739
2282
                            gpointer          set_template_data,
1740
2283
                            GtkSelectionData *selection)
1745
2288
  if (! template)
1746
2289
    return FALSE;
1747
2290
 
1748
 
  (* (GimpDndDropViewableFunc) set_template_func) (widget,
 
2291
  (* (GimpDndDropViewableFunc) set_template_func) (widget, x, y,
1749
2292
                                                   GIMP_VIEWABLE (template),
1750
2293
                                                   set_template_data);
1751
2294
 
1753
2296
}
1754
2297
 
1755
2298
 
1756
 
/************************/
1757
 
/*  tool dnd functions  */
1758
 
/************************/
 
2299
/********************************/
 
2300
/*  GimpToolInfo dnd functions  */
 
2301
/********************************/
1759
2302
 
1760
2303
static gboolean
1761
 
gimp_dnd_set_tool_data (GtkWidget        *widget,
1762
 
                        GCallback         set_tool_func,
1763
 
                        gpointer          set_tool_data,
1764
 
                        GtkSelectionData *selection)
 
2304
gimp_dnd_set_tool_info_data (GtkWidget        *widget,
 
2305
                             gint              x,
 
2306
                             gint              y,
 
2307
                             GCallback         set_tool_info_func,
 
2308
                             gpointer          set_tool_info_data,
 
2309
                             GtkSelectionData *selection)
1765
2310
{
1766
 
  GimpToolInfo *tool_info = gimp_selection_data_get_tool (selection,
1767
 
                                                          the_dnd_gimp);
 
2311
  GimpToolInfo *tool_info = gimp_selection_data_get_tool_info (selection,
 
2312
                                                               the_dnd_gimp);
1768
2313
 
1769
2314
  if (! tool_info)
1770
2315
    return FALSE;
1771
2316
 
1772
 
  (* (GimpDndDropViewableFunc) set_tool_func) (widget,
1773
 
                                               GIMP_VIEWABLE (tool_info),
1774
 
                                               set_tool_data);
 
2317
  (* (GimpDndDropViewableFunc) set_tool_info_func) (widget, x, y,
 
2318
                                                    GIMP_VIEWABLE (tool_info),
 
2319
                                                    set_tool_info_data);
1775
2320
 
1776
2321
  return TRUE;
1777
2322
}