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

« back to all changes in this revision

Viewing changes to libgimp/gimpimagecombobox.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:
22
22
 
23
23
#include "config.h"
24
24
 
 
25
#include <stdlib.h>
 
26
 
25
27
#include <gtk/gtk.h>
26
28
 
27
29
#include "libgimpwidgets/gimpwidgets.h"
28
30
 
29
31
#include "gimp.h"
30
32
 
 
33
#include "gimpuitypes.h"
31
34
#include "gimpimagecombobox.h"
32
35
#include "gimppixbuf.h"
33
36
 
34
37
 
35
 
#define MENU_THUMBNAIL_SIZE  24
 
38
#define THUMBNAIL_SIZE   24
 
39
#define WIDTH_REQUEST   200
 
40
 
 
41
 
 
42
typedef struct _GimpImageComboBoxClass GimpImageComboBoxClass;
 
43
 
 
44
struct _GimpImageComboBox
 
45
{
 
46
  GimpIntComboBox  parent_instance;
 
47
};
 
48
 
 
49
struct _GimpImageComboBoxClass
 
50
{
 
51
  GimpIntComboBoxClass  parent_class;
 
52
};
36
53
 
37
54
 
38
55
static void  gimp_image_combo_box_model_add (GtkListStore            *store,
41
58
                                             GimpImageConstraintFunc  constraint,
42
59
                                             gpointer                 data);
43
60
 
 
61
static void  gimp_image_combo_box_drag_data_received (GtkWidget        *widget,
 
62
                                                      GdkDragContext   *context,
 
63
                                                      gint              x,
 
64
                                                      gint              y,
 
65
                                                      GtkSelectionData *selection,
 
66
                                                      guint             info,
 
67
                                                      guint             time);
 
68
 
 
69
 
 
70
static const GtkTargetEntry target = { "application/x-gimp-image-id", 0 };
 
71
 
 
72
 
 
73
G_DEFINE_TYPE (GimpImageComboBox, gimp_image_combo_box, GIMP_TYPE_INT_COMBO_BOX)
 
74
 
 
75
 
 
76
static void
 
77
gimp_image_combo_box_class_init (GimpImageComboBoxClass *klass)
 
78
{
 
79
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
80
 
 
81
  widget_class->drag_data_received = gimp_image_combo_box_drag_data_received;
 
82
}
 
83
 
 
84
static void
 
85
gimp_image_combo_box_init (GimpImageComboBox *combo_box)
 
86
{
 
87
  gtk_drag_dest_set (GTK_WIDGET (combo_box),
 
88
                     GTK_DEST_DEFAULT_HIGHLIGHT |
 
89
                     GTK_DEST_DEFAULT_MOTION |
 
90
                     GTK_DEST_DEFAULT_DROP,
 
91
                     &target, 1,
 
92
                     GDK_ACTION_COPY);
 
93
}
44
94
 
45
95
/**
46
96
 * gimp_image_combo_box_new:
71
121
  gint32       *images;
72
122
  gint          num_images;
73
123
 
74
 
  combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
 
124
  combo_box = g_object_new (GIMP_TYPE_IMAGE_COMBO_BOX,
 
125
                            "width-request", WIDTH_REQUEST,
 
126
                            "ellipsize",     PANGO_ELLIPSIZE_MIDDLE,
 
127
                            NULL);
75
128
 
76
129
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
77
130
 
111
164
          g_free (image_name);
112
165
 
113
166
          thumb = gimp_image_get_thumbnail (images[i],
114
 
                                            MENU_THUMBNAIL_SIZE,
115
 
                                            MENU_THUMBNAIL_SIZE,
 
167
                                            THUMBNAIL_SIZE, THUMBNAIL_SIZE,
116
168
                                            GIMP_PIXBUF_SMALL_CHECKS);
117
169
 
118
170
          gtk_list_store_append (store, &iter);
129
181
        }
130
182
    }
131
183
}
 
184
 
 
185
static void
 
186
gimp_image_combo_box_drag_data_received (GtkWidget        *widget,
 
187
                                         GdkDragContext   *context,
 
188
                                         gint              x,
 
189
                                         gint              y,
 
190
                                         GtkSelectionData *selection,
 
191
                                         guint             info,
 
192
                                         guint             time)
 
193
{
 
194
  gchar *str;
 
195
 
 
196
  if ((selection->format != 8) || (selection->length < 1))
 
197
    {
 
198
      g_warning ("Received invalid image ID data!");
 
199
      return;
 
200
    }
 
201
 
 
202
  str = g_strndup ((const gchar *) selection->data, selection->length);
 
203
 
 
204
  if (g_utf8_validate (str, -1, NULL))
 
205
    {
 
206
      gint pid;
 
207
      gint ID;
 
208
 
 
209
      if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
 
210
          pid == gimp_getpid ())
 
211
        {
 
212
          gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), ID);
 
213
        }
 
214
    }
 
215
 
 
216
  g_free (str);
 
217
}