1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
4
* gimpdrawablecombobox.c
5
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
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.
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.
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.
27
#include "libgimpwidgets/gimpwidgets.h"
31
#include "gimpdrawablecombobox.h"
32
#include "gimppixbuf.h"
35
#define MENU_THUMBNAIL_SIZE 24
38
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
42
GimpDrawableConstraintFunc constraint,
47
* gimp_drawable_combo_box_new:
48
* @constraint: a #GimpDrawableConstraintFunc or %NULL
49
* @data: a pointer that is passed to @constraint
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.
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.
61
* Return value: a new #GimpIntComboBox.
66
gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
76
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
78
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
80
images = gimp_image_list (&num_images);
82
for (i = 0; i < num_images; i++)
87
drawables = gimp_image_get_layers (images[i], &num_drawables);
88
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
90
num_drawables, drawables,
94
drawables = gimp_image_get_channels (images[i], &num_drawables);
95
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
97
num_drawables, drawables,
104
if (gtk_tree_model_get_iter_first (model, &iter))
105
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
111
* gimp_channel_combo_box_new:
112
* @constraint: a #GimpDrawableConstraintFunc or %NULL
113
* @data: a pointer that is passed to @constraint
115
* Creates a new #GimpIntComboBox filled with all currently opened
116
* channels. See gimp_drawable_combo_box() for more info.
118
* Return value: a new #GimpIntComboBox.
123
gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
126
GtkWidget *combo_box;
133
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
135
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
137
images = gimp_image_list (&num_images);
139
for (i = 0; i < num_images; i++)
144
drawables = gimp_image_get_channels (images[i], &num_drawables);
145
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
147
num_drawables, drawables,
154
if (gtk_tree_model_get_iter_first (model, &iter))
155
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
161
* gimp_layer_combo_box_new:
162
* @constraint: a #GimpDrawableConstraintFunc or %NULL
163
* @data: a pointer that is passed to @constraint
165
* Creates a new #GimpIntComboBox filled with all currently opened
166
* layers. See gimp_drawable_combo_box() for more info.
168
* Return value: a new #GimpIntComboBox.
173
gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
176
GtkWidget *combo_box;
183
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
185
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
187
images = gimp_image_list (&num_images);
189
for (i = 0; i < num_images; i++)
194
drawables = gimp_image_get_layers (images[i], &num_drawables);
195
gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
197
num_drawables, drawables,
204
if (gtk_tree_model_get_iter_first (model, &iter))
205
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
211
gimp_drawable_combo_box_model_add (GtkListStore *store,
215
GimpDrawableConstraintFunc constraint,
222
for (i = 0; i < num_drawables; i++)
224
if (! constraint || (* constraint) (image, drawables[i], data))
226
gchar *image_name = gimp_image_get_name (image);
227
gchar *drawable_name = gimp_drawable_get_name (drawables[i]);
231
label = g_strdup_printf ("%s-%d/%s-%d",
233
drawable_name, drawables[i]);
235
g_free (drawable_name);
238
thumb = gimp_drawable_get_thumbnail (drawables[i],
241
GIMP_PIXBUF_SMALL_CHECKS);
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,
252
g_object_unref (thumb);