Commit f4b2b3c1 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

libgimp/Makefile.am libgimp/gimpui.h new file that holds pixbuf accessors

2004-04-21  Sven Neumann  <sven@gimp.org>

	* libgimp/Makefile.am
	* libgimp/gimpui.h
	* libgimp/gimppixbuf.[ch]: new file that holds pixbuf accessors
	to gimp data (drawable and image thumbnails for now).

	* libgimp/gimpdrawablecombobox.[ch]
	* libgimp/gimpimagecombobox.[ch]: new files with GimpIntComboBox
	constructors for image, drawable, channel and layer menus.

	* plug-ins/script-fu/script-fu-scripts.c: use the new functions
	instead of the gimpmenu API that is about to be deprecated.
parent ff06d050
2004-04-21 Sven Neumann <sven@gimp.org>
* libgimp/Makefile.am
* libgimp/gimpui.h
* libgimp/gimppixbuf.[ch]: new file that holds pixbuf accessors
to gimp data (drawable and image thumbnails for now).
* libgimp/gimpdrawablecombobox.[ch]
* libgimp/gimpimagecombobox.[ch]: new files with GimpIntComboBox
constructors for image, drawable, channel and layer menus.
* plug-ins/script-fu/script-fu-scripts.c: use the new functions
instead of the gimpmenu API that is about to be deprecated.
2004-04-20 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/fileops.pdb (file_load_thumbnail): removed
......
......@@ -206,6 +206,12 @@ libgimpui_2_0_la_SOURCES = \
gimpgradientmenu.h \
gimppatternmenu.c \
gimppatternmenu.h \
gimpdrawablecombobox.c \
gimpdrawablecombobox.h \
gimpimagecombobox.c \
gimpimagecombobox.h \
gimppixbuf.c \
gimppixbuf.h \
gimpexport.c \
gimpexport.h
......@@ -230,14 +236,17 @@ gimpinclude_HEADERS = \
gimpselection.h \
gimptile.h \
\
gimpexport.h \
gimpui.h \
gimpuitypes.h \
gimpmenu.h \
gimpbrushmenu.h \
gimpfontmenu.h \
gimpgradientmenu.h \
gimppatternmenu.h
gimppatternmenu.h \
gimppixbuf.h \
gimpdrawablecombobox.h \
gimpimagecombobox.h \
gimpexport.h
libgimp_2_0_la_LDFLAGS = \
-version-info $(LT_VERSION_INFO) \
......
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpdrawablecombobox.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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 <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gimp.h"
#include "gimpdrawablecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data);
static void gimp_drawable_combo_box_model_add_none (GtkListStore *store);
GtkWidget *
gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, 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 *drawables;
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
GtkWidget *
gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, 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 *drawables;
gint num_drawables;
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
GtkWidget *
gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, 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 *drawables;
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
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 gint
gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkTreeIter iter;
gint added = 0;
gint i;
for (i = 0; i < num_drawables; i++)
{
if (! constraint || (* constraint) (image, drawables[i], data))
{
gchar *image_name = gimp_image_get_name (image);
gchar *drawable_name = gimp_drawable_get_name (drawables[i]);
gchar *label;
GdkPixbuf *thumb;
label = g_strdup_printf ("%s-%d/%s-%d",
image_name, image,
drawable_name, drawables[i]);
g_free (drawable_name);
g_free (image_name);
thumb = gimp_drawable_get_thumbnail (drawables[i],
MENU_THUMBNAIL_SIZE,
MENU_THUMBNAIL_SIZE,
GIMP_PIXBUF_SMALL_CHECKS);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, drawables[i],
GIMP_INT_STORE_LABEL, label,
GIMP_INT_STORE_PIXBUF, thumb,
-1);
added++;
if (thumb)
g_object_unref (thumb);
g_free (label);
}
}
return added;
}
static void
gimp_drawable_combo_box_model_add_none (GtkListStore *store)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, _("(None)"),
-1);
}
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpdrawablecombobox.h
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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_DRAWABLE_COMBO_BOX_H__
#define __GIMP_DRAWABLE_COMBO_BOX_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
typedef gboolean (* GimpDrawableConstraintFunc) (gint32 image_id,
gint32 drawable_id,
gpointer data);
GtkWidget * gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
G_END_DECLS
#endif /* __GIMP_DRAWABLE_COMBO_BOX_H__ */
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpimagecombobox.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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 <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gimp.h"
#include "gimpimagecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static void gimp_image_combo_box_model_add (GtkListStore *store,
gint num_images,
gint32 *images,
GimpImageConstraintFunc constraint,
gpointer data);
static void gimp_image_combo_box_model_add_none (GtkListStore *store);
GtkWidget *
gimp_image_combo_box_new (GimpImageConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list (&num_images);
if (num_images > 0)
gimp_image_combo_box_model_add (GTK_LIST_STORE (model),
num_images, images,
constraint, data);
else
gimp_image_combo_box_model_add_none (GTK_LIST_STORE (model));
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_image_combo_box_model_add (GtkListStore *store,
gint num_images,
gint32 *images,
GimpImageConstraintFunc constraint,
gpointer data)
{
GtkTreeIter iter;
gint i;
for (i = 0; i < num_images; i++)
{
if (! constraint || (* constraint) (images[i], data))
{
gchar *image_name = gimp_image_get_name (images[i]);
gchar *label;
GdkPixbuf *thumb;
label = g_strdup_printf ("%s-%d", image_name, images[i]);
g_free (image_name);
thumb = gimp_image_get_thumbnail (images[i],
MENU_THUMBNAIL_SIZE,
MENU_THUMBNAIL_SIZE,
GIMP_PIXBUF_SMALL_CHECKS);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, images[i],
GIMP_INT_STORE_LABEL, label,
GIMP_INT_STORE_PIXBUF, thumb,
-1);
if (thumb)
g_object_unref (thumb);
g_free (label);
}
}
}
static void
gimp_image_combo_box_model_add_none (GtkListStore *store)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, _("(None)"),
-1);
}
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpimagecombobox.h
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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_IMAGE_COMBO_BOX_H__
#define __GIMP_IMAGE_COMBO_BOX_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
typedef gboolean (* GimpImageConstraintFunc) (gint32 image_id,
gpointer data);
GtkWidget * gimp_image_combo_box_new (GimpImageConstraintFunc constraint,
gpointer data);
G_END_DECLS
#endif /* __GIMP_DRAWABLE_COMBO_BOX_H__ */
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpdrawablecombobox.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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 <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gimp.h"
#include "gimpdrawablecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data);
static void gimp_drawable_combo_box_model_add_none (GtkListStore *store);
GtkWidget *
gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, 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 *drawables;
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
GtkWidget *
gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, 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 *drawables;
gint num_drawables;
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
GtkWidget *
gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, 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 *drawables;
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
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 gint
gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkTreeIter iter;
gint added = 0;
gint i;
for (i = 0; i < num_drawables; i++)
{
if (! constraint || (* constraint) (image, drawables[i], data))
{
gchar *image_name = gimp_image_get_name (image);
gchar *drawable_name = gimp_drawable_get_name (drawables[i]);
gchar *label;
GdkPixbuf *thumb;
label = g_strdup_printf ("%s-%d/%s-%d",
image_name, image,
drawable_name, drawables[i]);
g_free (drawable_name);
g_free (image_name);
thumb = gimp_drawable_get_thumbnail (drawables[i],
MENU_THUMBNAIL_SIZE,
MENU_THUMBNAIL_SIZE,
GIMP_PIXBUF_SMALL_CHECKS);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, drawables[i],
GIMP_INT_STORE_LABEL, label,
GIMP_INT_STORE_PIXBUF, thumb,
-1);
added++;
if (thumb)
g_object_unref (thumb);
g_free (label);
}
}