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

« back to all changes in this revision

Viewing changes to libgimp/gimpdrawablecombobox.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
 
 * gimpdrawablecombobox.c
5
 
 * Copyright (C) 2004 Sven Neumann <sven@gimp.org>
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
 
 * Lesser 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 "gimpdrawablecombobox.h"
32
 
#include "gimppixbuf.h"
33
 
 
34
 
 
35
 
#define MENU_THUMBNAIL_SIZE  24
36
 
 
37
 
 
38
 
static gint  gimp_drawable_combo_box_model_add (GtkListStore               *store,
39
 
                                                gint32                      image,
40
 
                                                gint                        num_drawables,
41
 
                                                gint32                     *drawables,
42
 
                                                GimpDrawableConstraintFunc  constraint,
43
 
                                                gpointer                    data);
44
 
 
45
 
 
46
 
/**
47
 
 * gimp_drawable_combo_box_new:
48
 
 * @constraint: a #GimpDrawableConstraintFunc or %NULL
49
 
 * @data:       a pointer that is passed to @constraint
50
 
 *
51
 
 * Creates a new #GimpIntComboBox filled with all currently opened
52
 
 * drawables. If a @constraint function is specified, it is called for
53
 
 * each drawable and only if the function returns %TRUE, the drawable
54
 
 * is added to the combobox.
55
 
 *
56
 
 * You should use gimp_int_combo_box_connect() to initialize and connect
57
 
 * the combo.  Use gimp_int_combo_box_set_active() to get the active
58
 
 * drawable ID and gimp_int_combo_box_get_active() to retrieve the ID
59
 
 * of the selected drawable.
60
 
 *
61
 
 * Return value: a new #GimpIntComboBox.
62
 
 *
63
 
 * Since: GIMP 2.2
64
 
 **/
65
 
GtkWidget *
66
 
gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
67
 
                             gpointer                   data)
68
 
{
69
 
  GtkWidget    *combo_box;
70
 
  GtkTreeModel *model;
71
 
  GtkTreeIter   iter;
72
 
  gint32       *images;
73
 
  gint          num_images;
74
 
  gint          i;
75
 
 
76
 
  combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
77
 
 
78
 
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
79
 
 
80
 
  images = gimp_image_list (&num_images);
81
 
 
82
 
  for (i = 0; i < num_images; i++)
83
 
    {
84
 
      gint32 *drawables;
85
 
      gint    num_drawables;
86
 
 
87
 
      drawables = gimp_image_get_layers (images[i], &num_drawables);
88
 
      gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
89
 
                                         images[i],
90
 
                                         num_drawables, drawables,
91
 
                                         constraint, data);
92
 
      g_free (drawables);
93
 
 
94
 
      drawables = gimp_image_get_channels (images[i], &num_drawables);
95
 
      gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
96
 
                                         images[i],
97
 
                                         num_drawables, drawables,
98
 
                                         constraint, data);
99
 
      g_free (drawables);
100
 
    }
101
 
 
102
 
  g_free (images);
103
 
 
104
 
  if (gtk_tree_model_get_iter_first (model, &iter))
105
 
    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
106
 
 
107
 
  return combo_box;
108
 
}
109
 
 
110
 
/**
111
 
 * gimp_channel_combo_box_new:
112
 
 * @constraint: a #GimpDrawableConstraintFunc or %NULL
113
 
 * @data:       a pointer that is passed to @constraint
114
 
 *
115
 
 * Creates a new #GimpIntComboBox filled with all currently opened
116
 
 * channels. See gimp_drawable_combo_box() for more info.
117
 
 *
118
 
 * Return value: a new #GimpIntComboBox.
119
 
 *
120
 
 * Since: GIMP 2.2
121
 
 **/
122
 
GtkWidget *
123
 
gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
124
 
                            gpointer                   data)
125
 
{
126
 
  GtkWidget    *combo_box;
127
 
  GtkTreeModel *model;
128
 
  GtkTreeIter   iter;
129
 
  gint32       *images;
130
 
  gint          num_images;
131
 
  gint          i;
132
 
 
133
 
  combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
134
 
 
135
 
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
136
 
 
137
 
  images = gimp_image_list (&num_images);
138
 
 
139
 
  for (i = 0; i < num_images; i++)
140
 
    {
141
 
      gint32 *drawables;
142
 
      gint    num_drawables;
143
 
 
144
 
      drawables = gimp_image_get_channels (images[i], &num_drawables);
145
 
      gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
146
 
                                         images[i],
147
 
                                         num_drawables, drawables,
148
 
                                         constraint, data);
149
 
      g_free (drawables);
150
 
    }
151
 
 
152
 
  g_free (images);
153
 
 
154
 
  if (gtk_tree_model_get_iter_first (model, &iter))
155
 
    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
156
 
 
157
 
  return combo_box;
158
 
}
159
 
 
160
 
/**
161
 
 * gimp_layer_combo_box_new:
162
 
 * @constraint: a #GimpDrawableConstraintFunc or %NULL
163
 
 * @data:       a pointer that is passed to @constraint
164
 
 *
165
 
 * Creates a new #GimpIntComboBox filled with all currently opened
166
 
 * layers. See gimp_drawable_combo_box() for more info.
167
 
 *
168
 
 * Return value: a new #GimpIntComboBox.
169
 
 *
170
 
 * Since: GIMP 2.2
171
 
 **/
172
 
GtkWidget *
173
 
gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
174
 
                          gpointer                   data)
175
 
{
176
 
  GtkWidget    *combo_box;
177
 
  GtkTreeModel *model;
178
 
  GtkTreeIter   iter;
179
 
  gint32       *images;
180
 
  gint          num_images;
181
 
  gint          i;
182
 
 
183
 
  combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
184
 
 
185
 
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
186
 
 
187
 
  images = gimp_image_list (&num_images);
188
 
 
189
 
  for (i = 0; i < num_images; i++)
190
 
    {
191
 
      gint32 *drawables;
192
 
      gint    num_drawables;
193
 
 
194
 
      drawables = gimp_image_get_layers (images[i], &num_drawables);
195
 
      gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
196
 
                                         images[i],
197
 
                                         num_drawables, drawables,
198
 
                                         constraint, data);
199
 
      g_free (drawables);
200
 
    }
201
 
 
202
 
  g_free (images);
203
 
 
204
 
  if (gtk_tree_model_get_iter_first (model, &iter))
205
 
    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
206
 
 
207
 
  return combo_box;
208
 
}
209
 
 
210
 
static gint
211
 
gimp_drawable_combo_box_model_add (GtkListStore               *store,
212
 
                                   gint32                      image,
213
 
                                   gint                        num_drawables,
214
 
                                   gint32                     *drawables,
215
 
                                   GimpDrawableConstraintFunc  constraint,
216
 
                                   gpointer                    data)
217
 
{
218
 
  GtkTreeIter  iter;
219
 
  gint         added = 0;
220
 
  gint         i;
221
 
 
222
 
  for (i = 0; i < num_drawables; i++)
223
 
    {
224
 
      if (! constraint || (* constraint) (image, drawables[i], data))
225
 
        {
226
 
          gchar     *image_name    = gimp_image_get_name (image);
227
 
          gchar     *drawable_name = gimp_drawable_get_name (drawables[i]);
228
 
          gchar     *label;
229
 
          GdkPixbuf *thumb;
230
 
 
231
 
          label = g_strdup_printf ("%s-%d/%s-%d",
232
 
                                   image_name,    image,
233
 
                                   drawable_name, drawables[i]);
234
 
 
235
 
          g_free (drawable_name);
236
 
          g_free (image_name);
237
 
 
238
 
          thumb = gimp_drawable_get_thumbnail (drawables[i],
239
 
                                               MENU_THUMBNAIL_SIZE,
240
 
                                               MENU_THUMBNAIL_SIZE,
241
 
                                               GIMP_PIXBUF_SMALL_CHECKS);
242
 
 
243
 
          gtk_list_store_append (store, &iter);
244
 
          gtk_list_store_set (store, &iter,
245
 
                              GIMP_INT_STORE_VALUE,  drawables[i],
246
 
                              GIMP_INT_STORE_LABEL,  label,
247
 
                              GIMP_INT_STORE_PIXBUF, thumb,
248
 
                              -1);
249
 
          added++;
250
 
 
251
 
          if (thumb)
252
 
            g_object_unref (thumb);
253
 
 
254
 
          g_free (label);
255
 
        }
256
 
    }
257
 
 
258
 
  return added;
259
 
}