Index: libgimp/Makefile.am =================================================================== RCS file: /cvs/gnome/gimp/libgimp/Makefile.am,v retrieving revision 1.166 diff -u -p -r1.166 Makefile.am --- libgimp/Makefile.am 26 Jun 2006 01:47:19 -0000 1.166 +++ libgimp/Makefile.am 15 Nov 2006 20:56:24 -0000 @@ -279,6 +279,8 @@ libgimpui_2_0_la_sources = \ gimpprogressbar.h \ gimpselectbutton.c \ gimpselectbutton.h \ + gimpvectorscombobox.c \ + gimpvectorscombobox.h \ gimpzoompreview.c \ gimpzoompreview.h Index: libgimp/gimpui.h =================================================================== RCS file: /cvs/gnome/gimp/libgimp/gimpui.h,v retrieving revision 1.35 diff -u -p -r1.35 gimpui.h --- libgimp/gimpui.h 26 Jun 2006 01:47:19 -0000 1.35 +++ libgimp/gimpui.h 15 Nov 2006 20:56:24 -0000 @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include Index: libgimp/gimpuitypes.h =================================================================== RCS file: /cvs/gnome/gimp/libgimp/gimpuitypes.h,v retrieving revision 1.14 diff -u -p -r1.14 gimpuitypes.h --- libgimp/gimpuitypes.h 26 Jun 2006 01:47:20 -0000 1.14 +++ libgimp/gimpuitypes.h 15 Nov 2006 20:56:24 -0000 @@ -38,6 +38,7 @@ typedef struct _GimpZoomPreview typedef struct _GimpDrawableComboBox GimpDrawableComboBox; typedef struct _GimpChannelComboBox GimpChannelComboBox; typedef struct _GimpLayerComboBox GimpLayerComboBox; +typedef struct _GimpVectorsComboBox GimpVectorsComboBox; typedef struct _GimpImageComboBox GimpImageComboBox; typedef struct _GimpSelectButton GimpSelectButton; Index: libgimp/gimpvectorscombobox.c =================================================================== RCS file: libgimp/gimpvectorscombobox.c diff -N libgimp/gimpvectorscombobox.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ libgimp/gimpvectorscombobox.c 15 Nov 2006 20:56:24 -0000 @@ -0,0 +1,231 @@ +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball + * + * gimpvectorscombobox.c + * Copyright (C) 2006 Simon Budig + * Copyright (C) 2004 Sven Neumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include + +#include "libgimpwidgets/gimpwidgets.h" + +#include "gimp.h" + +#include "gimpuitypes.h" +#include "gimpvectorscombobox.h" + + +#define WIDTH_REQUEST 200 + + +typedef struct _GimpVectorsComboBoxClass GimpVectorsComboBoxClass; + +struct _GimpVectorsComboBox +{ + GimpIntComboBox parent_instance; +}; + +struct _GimpVectorsComboBoxClass +{ + GimpIntComboBoxClass parent_class; +}; + + +static void gimp_vectors_combo_box_model_add (GtkListStore *store, + gint32 image, + gint num_vectors, + gint32 *vectors, + GimpVectorsConstraintFunc constraint, + gpointer data); + +static void gimp_vectors_combo_box_drag_data_received (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection, + guint info, + guint time); + + +static const GtkTargetEntry targets[] = +{ + { "application/x-gimp-vectors-id", 0 } +}; + + +G_DEFINE_TYPE (GimpVectorsComboBox, gimp_vectors_combo_box, + GIMP_TYPE_INT_COMBO_BOX) + + +static void +gimp_vectors_combo_box_class_init (GimpVectorsComboBoxClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->drag_data_received = gimp_vectors_combo_box_drag_data_received; +} + +static void +gimp_vectors_combo_box_init (GimpVectorsComboBox *combo_box) +{ + gtk_drag_dest_set (GTK_WIDGET (combo_box), + GTK_DEST_DEFAULT_HIGHLIGHT | + GTK_DEST_DEFAULT_MOTION | + GTK_DEST_DEFAULT_DROP, + targets, 1, + GDK_ACTION_COPY); +} + +/** + * gimp_vectors_combo_box_new: + * @constraint: a #GimpVectorsConstraintFunc or %NULL + * @data: a pointer that is passed to @constraint + * + * Creates a new #GimpIntComboBox filled with all currently opened + * vectors objects. If a @constraint function is specified, it is called for + * each vectors object and only if the function returns %TRUE, the vectors + * object is added to the combobox. + * + * You should use gimp_int_combo_box_connect() to initialize and connect + * the combo. Use gimp_int_combo_box_set_active() to set the active + * vectors ID and gimp_int_combo_box_get_active() to retrieve the ID + * of the selected vectors object. + * + * Return value: a new #GimpIntComboBox. + * + * Since: GIMP 2.4 + **/ +GtkWidget * +gimp_vectors_combo_box_new (GimpVectorsConstraintFunc constraint, + gpointer data) +{ + GtkWidget *combo_box; + GtkTreeModel *model; + GtkTreeIter iter; + gint32 *images; + gint num_images; + gint i; + + combo_box = g_object_new (GIMP_TYPE_VECTORS_COMBO_BOX, + "width-request", WIDTH_REQUEST, + "ellipsize", PANGO_ELLIPSIZE_MIDDLE, + NULL); + + model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)); + + images = gimp_image_list (&num_images); + + for (i = 0; i < num_images; i++) + { + gint32 *vectors; + gint num_vectors; + + vectors = gimp_image_get_vectors (images[i], &num_vectors); + gimp_vectors_combo_box_model_add (GTK_LIST_STORE (model), + images[i], + num_vectors, vectors, + constraint, data); + g_free (vectors); + } + + g_free (images); + + if (gtk_tree_model_get_iter_first (model, &iter)) + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter); + + return combo_box; +} + + +static void +gimp_vectors_combo_box_model_add (GtkListStore *store, + gint32 image, + gint num_vectors, + gint32 *vectors, + GimpVectorsConstraintFunc constraint, + gpointer data) +{ + GtkTreeIter iter; + gint i; + + for (i = 0; i < num_vectors; i++) + { + if (! constraint || (* constraint) (image, vectors[i], data)) + { + gchar *image_name = gimp_image_get_name (image); + gchar *vectors_name = gimp_vectors_get_name (vectors[i]); + gchar *label; + GdkPixbuf *thumb; + + label = g_strdup_printf ("%s-%d/%s-%d", + image_name, image, + vectors_name, vectors[i]); + + g_free (vectors_name); + g_free (image_name); + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + GIMP_INT_STORE_VALUE, vectors[i], + GIMP_INT_STORE_LABEL, label, + GIMP_INT_STORE_PIXBUF, NULL, + -1); + + g_free (label); + } + } +} + +static void +gimp_vectors_combo_box_drag_data_received (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection, + guint info, + guint time) +{ + gchar *str; + + if ((selection->format != 8) || (selection->length < 1)) + { + g_warning ("Received invalid vectors ID data!"); + return; + } + + str = g_strndup ((const gchar *) selection->data, selection->length); + + if (g_utf8_validate (str, -1, NULL)) + { + gint pid; + gint ID; + + if (sscanf (str, "%i:%i", &pid, &ID) == 2 && + pid == gimp_getpid ()) + { + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), ID); + } + } + + g_free (str); +} Index: libgimp/gimpvectorscombobox.h =================================================================== RCS file: libgimp/gimpvectorscombobox.h diff -N libgimp/gimpvectorscombobox.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ libgimp/gimpvectorscombobox.h 15 Nov 2006 20:56:24 -0000 @@ -0,0 +1,49 @@ +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball + * + * gimpvectorscombobox.h + * Copyright (C) 2006 Simon Budig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_VECTORS_COMBO_BOX_H__ +#define __GIMP_VECTORS_COMBO_BOX_H__ + + +G_BEGIN_DECLS + +/* For information look into the C source or the html documentation */ + + +#define GIMP_TYPE_VECTORS_COMBO_BOX (gimp_vectors_combo_box_get_type ()) +#define GIMP_VECTORS_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_VECTORS_COMBO_BOX, GimpVectorsComboBox)) +#define GIMP_IS_VECTORS_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_VECTORS_COMBO_BOX) + +typedef gboolean (* GimpVectorsConstraintFunc) (gint32 image_id, + gint32 vectors_id, + gpointer data); + + +GType gimp_vectors_combo_box_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_vectors_combo_box_new (GimpVectorsConstraintFunc constraint, + gpointer data); + + +G_END_DECLS + +#endif /* __GIMP_VECTORS_COMBO_BOX_H__ */