2000-05-09 01:45:16 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
1998-01-25 18:26:47 +08:00
|
|
|
*
|
2000-05-31 14:15:06 +08:00
|
|
|
* gimpmenu.c
|
|
|
|
*
|
1998-01-25 18:26:47 +08:00
|
|
|
* This library is free software; you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-01-25 18:26:47 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
2000-05-09 01:45:16 +08:00
|
|
|
* 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
|
1998-01-25 18:26:47 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-04-13 13:44:11 +08:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2000-05-09 01:45:16 +08:00
|
|
|
*/
|
|
|
|
|
2002-05-13 21:21:55 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2004-04-22 07:09:16 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gimp.h"
|
2004-04-22 07:09:16 +08:00
|
|
|
|
2004-07-31 07:03:45 +08:00
|
|
|
#include "gimppixbuf.h"
|
|
|
|
|
2004-04-22 07:09:16 +08:00
|
|
|
#undef GIMP_DISABLE_DEPRECATED
|
|
|
|
#include "gimpmenu.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-05-13 21:21:55 +08:00
|
|
|
#include "libgimp-intl.h"
|
2002-01-30 22:54:27 +08:00
|
|
|
|
2003-06-19 21:01:49 +08:00
|
|
|
|
2000-05-09 01:45:16 +08:00
|
|
|
#define MENU_THUMBNAIL_WIDTH 24
|
|
|
|
#define MENU_THUMBNAIL_HEIGHT 24
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-06-19 21:01:49 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
/* local function prototypes */
|
2003-06-19 21:01:49 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
static GtkWidget * gimp_menu_make_menu (GimpMenuCallback callback,
|
|
|
|
gpointer data);
|
|
|
|
static GtkWidget * gimp_menu_add_item (GtkWidget *menu,
|
|
|
|
const gchar *image_name,
|
|
|
|
const gchar *drawable_name,
|
2003-07-24 21:09:01 +08:00
|
|
|
gint32 any_ID);
|
2004-04-22 00:50:13 +08:00
|
|
|
static GtkWidget * gimp_menu_add_empty (GtkWidget *menu);
|
2003-07-24 21:09:01 +08:00
|
|
|
static GtkWidget * gimp_menu_make_preview (gint32 any_ID,
|
|
|
|
gboolean is_image,
|
2003-07-24 01:48:32 +08:00
|
|
|
gint width,
|
|
|
|
gint height);
|
2003-07-24 21:09:01 +08:00
|
|
|
static void gimp_menu_callback (GtkWidget *widget,
|
|
|
|
gpointer any_ID);
|
2003-07-24 01:48:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-03-23 17:58:33 +08:00
|
|
|
/**
|
|
|
|
* gimp_image_menu_new:
|
|
|
|
* @constraint:
|
|
|
|
* @callback:
|
|
|
|
* @data:
|
|
|
|
* @active_image:
|
|
|
|
*
|
|
|
|
* Use gimp_image_combo_box_new() instead.
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*/
|
2000-05-31 14:15:06 +08:00
|
|
|
GtkWidget *
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_image_menu_new (GimpConstraintFunc constraint,
|
2006-04-12 18:53:28 +08:00
|
|
|
GimpMenuCallback callback,
|
|
|
|
gpointer data,
|
|
|
|
gint32 active_image)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
2002-05-13 21:21:55 +08:00
|
|
|
gchar *name;
|
2001-08-30 01:48:28 +08:00
|
|
|
gchar *label;
|
|
|
|
gint32 *images;
|
2003-07-24 21:09:01 +08:00
|
|
|
gint32 image = -1;
|
2003-07-24 01:48:32 +08:00
|
|
|
gint n_images;
|
2001-08-30 01:48:28 +08:00
|
|
|
gint i, k;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
g_return_val_if_fail (callback != NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
menu = gimp_menu_make_menu (callback, data);
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
images = gimp_image_list (&n_images);
|
|
|
|
|
|
|
|
for (i = 0, k = 0; i < n_images; i++)
|
|
|
|
if (! constraint || (* constraint) (images[i], -1, data))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-04-12 18:53:28 +08:00
|
|
|
name = gimp_image_get_name (images[i]);
|
|
|
|
label = g_strdup_printf ("%s-%d", name, images[i]);
|
|
|
|
g_free (name);
|
2001-08-30 01:48:28 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
gimp_menu_add_item (menu, label, NULL, images[i]);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
g_free (label);
|
2003-07-24 01:48:32 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
if (images[i] == active_image)
|
2003-07-24 21:09:01 +08:00
|
|
|
{
|
|
|
|
image = active_image;
|
|
|
|
gtk_menu_set_active (GTK_MENU (menu), k);
|
|
|
|
}
|
|
|
|
else if (image == -1)
|
2004-01-12 19:00:45 +08:00
|
|
|
{
|
|
|
|
image = images[i];
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
k += 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (k == 0)
|
2004-04-22 00:50:13 +08:00
|
|
|
gimp_menu_add_empty (menu);
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2004-01-12 19:00:45 +08:00
|
|
|
(* callback) (image, data);
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
g_free (images);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
2005-03-23 17:58:33 +08:00
|
|
|
/**
|
|
|
|
* gimp_layer_menu_new:
|
|
|
|
* @constraint:
|
|
|
|
* @callback:
|
|
|
|
* @data:
|
|
|
|
* @active_layer:
|
|
|
|
*
|
|
|
|
* Use gimp_layer_combo_box_new() instead.
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*/
|
2000-05-31 14:15:06 +08:00
|
|
|
GtkWidget *
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_layer_menu_new (GimpConstraintFunc constraint,
|
2006-04-12 18:53:28 +08:00
|
|
|
GimpMenuCallback callback,
|
|
|
|
gpointer data,
|
|
|
|
gint32 active_layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
2001-08-30 01:48:28 +08:00
|
|
|
gchar *image_label;
|
|
|
|
gint32 *images;
|
|
|
|
gint32 *layers;
|
2003-07-24 01:48:32 +08:00
|
|
|
gint32 layer = -1;
|
|
|
|
gint n_images;
|
|
|
|
gint n_layers;
|
2001-08-30 01:48:28 +08:00
|
|
|
gint i, j, k;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
g_return_val_if_fail (callback != NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
menu = gimp_menu_make_menu (callback, data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
images = gimp_image_list (&n_images);
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
for (i = 0, k = 0; i < n_images; i++)
|
|
|
|
if (! constraint || (* constraint) (images[i], -1, data))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-07-24 01:48:32 +08:00
|
|
|
gchar *name;
|
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
name = gimp_image_get_name (images[i]);
|
|
|
|
image_label = g_strdup_printf ("%s-%d", name, images[i]);
|
|
|
|
g_free (name);
|
2001-08-30 01:48:28 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
layers = gimp_image_get_layers (images[i], &n_layers);
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
for (j = 0; j < n_layers; j++)
|
|
|
|
if (! constraint || (* constraint) (images[i], layers[j], data))
|
|
|
|
{
|
|
|
|
name = gimp_drawable_get_name (layers[j]);
|
2003-07-24 21:09:01 +08:00
|
|
|
gimp_menu_add_item (menu, image_label, name, layers[j]);
|
2006-04-12 18:53:28 +08:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
if (layers[j] == active_layer)
|
|
|
|
{
|
|
|
|
layer = active_layer;
|
|
|
|
gtk_menu_set_active (GTK_MENU (menu), k);
|
|
|
|
}
|
|
|
|
else if (layer == -1)
|
2004-01-12 19:00:45 +08:00
|
|
|
{
|
|
|
|
layer = layers[j];
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
k += 1;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
g_free (image_label);
|
2003-07-24 21:09:01 +08:00
|
|
|
g_free (layers);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2003-07-01 23:06:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (images);
|
|
|
|
|
|
|
|
if (k == 0)
|
2004-04-22 00:50:13 +08:00
|
|
|
gimp_menu_add_empty (menu);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-01-12 19:00:45 +08:00
|
|
|
(* callback) (layer, data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
2005-03-23 17:58:33 +08:00
|
|
|
/**
|
|
|
|
* gimp_channel_menu_new:
|
|
|
|
* @constraint:
|
|
|
|
* @callback:
|
|
|
|
* @data:
|
|
|
|
* @active_channel:
|
|
|
|
*
|
|
|
|
* Use gimp_channel_combo_box_new() instead.
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*/
|
2000-05-31 14:15:06 +08:00
|
|
|
GtkWidget *
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_channel_menu_new (GimpConstraintFunc constraint,
|
2006-04-12 18:53:28 +08:00
|
|
|
GimpMenuCallback callback,
|
|
|
|
gpointer data,
|
|
|
|
gint32 active_channel)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
2001-08-30 01:48:28 +08:00
|
|
|
gchar *image_label;
|
|
|
|
gint32 *images;
|
|
|
|
gint32 *channels;
|
|
|
|
gint32 channel;
|
2003-07-24 01:48:32 +08:00
|
|
|
gint n_images;
|
|
|
|
gint n_channels;
|
2001-08-30 01:48:28 +08:00
|
|
|
gint i, j, k;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
g_return_val_if_fail (callback != NULL, NULL);
|
|
|
|
|
|
|
|
menu = gimp_menu_make_menu (callback, data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
channel = -1;
|
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
images = gimp_image_list (&n_images);
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
for (i = 0, k = 0; i < n_images; i++)
|
|
|
|
if (! constraint || (* constraint) (images[i], -1, data))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-07-24 01:48:32 +08:00
|
|
|
gchar *name;
|
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
name = gimp_image_get_name (images[i]);
|
|
|
|
image_label = g_strdup_printf ("%s-%d", name, images[i]);
|
|
|
|
g_free (name);
|
2001-08-30 01:48:28 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
channels = gimp_image_get_channels (images[i], &n_channels);
|
2003-07-01 23:06:06 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
for (j = 0; j < n_channels; j++)
|
|
|
|
if (! constraint || (* constraint) (images[i], channels[j], data))
|
|
|
|
{
|
|
|
|
name = gimp_drawable_get_name (channels[j]);
|
2003-07-24 21:09:01 +08:00
|
|
|
gimp_menu_add_item (menu, image_label, name, channels[j]);
|
2006-04-12 18:53:28 +08:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
if (channels[j] == active_channel)
|
|
|
|
{
|
|
|
|
channel = active_channel;
|
|
|
|
gtk_menu_set_active (GTK_MENU (menu), k);
|
|
|
|
}
|
|
|
|
else if (channel == -1)
|
2004-01-12 19:00:45 +08:00
|
|
|
{
|
|
|
|
channel = channels[j];
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
k += 1;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
g_free (image_label);
|
2003-07-24 21:09:01 +08:00
|
|
|
g_free (channels);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2003-07-01 23:06:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (images);
|
|
|
|
|
|
|
|
if (k == 0)
|
2004-04-22 00:50:13 +08:00
|
|
|
gimp_menu_add_empty (menu);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-01-12 19:00:45 +08:00
|
|
|
(* callback) (channel, data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
2005-03-23 17:58:33 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_menu_new:
|
|
|
|
* @constraint:
|
|
|
|
* @callback:
|
|
|
|
* @data:
|
|
|
|
* @active_drawable:
|
|
|
|
*
|
|
|
|
* Use gimp_drawable_combo_box_new() instead.
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*/
|
2000-05-31 14:15:06 +08:00
|
|
|
GtkWidget *
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_drawable_menu_new (GimpConstraintFunc constraint,
|
2006-04-12 18:53:28 +08:00
|
|
|
GimpMenuCallback callback,
|
|
|
|
gpointer data,
|
|
|
|
gint32 active_drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
2001-08-30 01:48:28 +08:00
|
|
|
gchar *name;
|
|
|
|
gchar *image_label;
|
|
|
|
gint32 *images;
|
|
|
|
gint32 *layers;
|
|
|
|
gint32 *channels;
|
|
|
|
gint32 drawable;
|
2003-07-24 01:48:32 +08:00
|
|
|
gint n_images;
|
|
|
|
gint n_layers;
|
|
|
|
gint n_channels;
|
2001-08-30 01:48:28 +08:00
|
|
|
gint i, j, k;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
menu = gimp_menu_make_menu (callback, data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
drawable = -1;
|
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
images = gimp_image_list (&n_images);
|
2000-05-09 01:45:16 +08:00
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
for (i = 0, k = 0; i < n_images; i++)
|
|
|
|
if (! constraint || (* constraint) (images[i], -1, data))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-04-12 18:53:28 +08:00
|
|
|
name = gimp_image_get_name (images[i]);
|
|
|
|
image_label = g_strdup_printf ("%s-%d", name, images[i]);
|
|
|
|
g_free (name);
|
2001-08-30 01:48:28 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
layers = gimp_image_get_layers (images[i], &n_layers);
|
|
|
|
channels = gimp_image_get_channels (images[i], &n_channels);
|
2000-05-09 01:45:16 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
for (j = 0; j < n_layers; j++)
|
|
|
|
if (! constraint || (* constraint) (images[i], layers[j], data))
|
|
|
|
{
|
|
|
|
name = gimp_drawable_get_name (layers[j]);
|
2003-07-24 21:09:01 +08:00
|
|
|
gimp_menu_add_item (menu, image_label, name, layers[j]);
|
2006-04-12 18:53:28 +08:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
if (layers[j] == active_drawable)
|
|
|
|
{
|
|
|
|
drawable = active_drawable;
|
|
|
|
gtk_menu_set_active (GTK_MENU (menu), k);
|
|
|
|
}
|
|
|
|
else if (drawable == -1)
|
2004-01-12 19:00:45 +08:00
|
|
|
{
|
|
|
|
drawable = layers[j];
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
k += 1;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
for (j = 0; j < n_channels; j++)
|
|
|
|
if (! constraint || (* constraint) (images[i], channels[j], data))
|
|
|
|
{
|
|
|
|
name = gimp_drawable_get_name (channels[j]);
|
2003-07-24 21:09:01 +08:00
|
|
|
gimp_menu_add_item (menu, image_label, name, channels[j]);
|
2006-04-12 18:53:28 +08:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
if (channels[j] == active_drawable)
|
|
|
|
{
|
|
|
|
drawable = active_drawable;
|
|
|
|
gtk_menu_set_active (GTK_MENU (menu), k);
|
|
|
|
}
|
|
|
|
else if (drawable == -1)
|
2004-01-12 19:00:45 +08:00
|
|
|
{
|
|
|
|
drawable = channels[j];
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
k += 1;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
g_free (image_label);
|
2003-07-24 21:09:01 +08:00
|
|
|
g_free (layers);
|
|
|
|
g_free (channels);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2003-07-01 23:06:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (images);
|
|
|
|
|
|
|
|
if (k == 0)
|
2004-04-22 00:50:13 +08:00
|
|
|
gimp_menu_add_empty (menu);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-01-12 19:00:45 +08:00
|
|
|
(* callback) (drawable, data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-01 23:06:06 +08:00
|
|
|
/* private functions */
|
|
|
|
|
2003-07-24 01:48:32 +08:00
|
|
|
static GtkWidget *
|
|
|
|
gimp_menu_make_menu (GimpMenuCallback callback,
|
2006-04-12 18:53:28 +08:00
|
|
|
gpointer data)
|
2003-07-24 01:48:32 +08:00
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
|
|
|
|
|
|
|
menu = gtk_menu_new ();
|
|
|
|
g_object_set_data (G_OBJECT (menu), "gimp-menu-callback", callback);
|
|
|
|
g_object_set_data (G_OBJECT (menu), "gimp-menu-callback-data", data);
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
gimp_menu_add_item (GtkWidget *menu,
|
|
|
|
const gchar *image_name,
|
|
|
|
const gchar *drawable_name,
|
2003-07-24 21:09:01 +08:00
|
|
|
gint32 any_ID)
|
2003-07-24 01:48:32 +08:00
|
|
|
{
|
|
|
|
GtkWidget *menuitem;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *vbox;
|
2003-07-24 21:09:01 +08:00
|
|
|
GtkWidget *preview;
|
|
|
|
GtkWidget *label;
|
|
|
|
gchar *str;
|
2003-07-24 01:48:32 +08:00
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
if (drawable_name)
|
|
|
|
str = g_strdup_printf ("%s/%s-%d", image_name, drawable_name, any_ID);
|
|
|
|
else
|
|
|
|
str = g_strdup (image_name);
|
2003-07-24 01:48:32 +08:00
|
|
|
|
|
|
|
menuitem = gtk_menu_item_new ();
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
G_CALLBACK (gimp_menu_callback),
|
2003-07-24 21:09:01 +08:00
|
|
|
GINT_TO_POINTER (any_ID));
|
2003-07-24 01:48:32 +08:00
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (menuitem), hbox);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
preview = gimp_menu_make_preview (any_ID, drawable_name == NULL,
|
|
|
|
MENU_THUMBNAIL_WIDTH,
|
|
|
|
MENU_THUMBNAIL_HEIGHT);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), preview);
|
|
|
|
gtk_widget_show (preview);
|
2003-07-24 01:48:32 +08:00
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
label = gtk_label_new (str);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
2003-07-24 01:48:32 +08:00
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
g_free (str);
|
2003-07-24 01:48:32 +08:00
|
|
|
|
|
|
|
return menuitem;
|
|
|
|
}
|
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
static GtkWidget *
|
2004-04-22 00:50:13 +08:00
|
|
|
gimp_menu_add_empty (GtkWidget *menu)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-07-24 21:09:01 +08:00
|
|
|
GtkWidget *menuitem;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-04-22 00:50:13 +08:00
|
|
|
menuitem = gtk_menu_item_new_with_label (_("(Empty)"));
|
2003-07-24 21:09:01 +08:00
|
|
|
gtk_widget_set_sensitive (menuitem, FALSE);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
return menuitem;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-09-19 08:40:27 +08:00
|
|
|
|
2003-07-24 21:09:01 +08:00
|
|
|
static GtkWidget *
|
|
|
|
gimp_menu_make_preview (gint32 any_ID,
|
|
|
|
gboolean is_image,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
1999-06-24 07:01:14 +08:00
|
|
|
{
|
2004-07-31 07:03:45 +08:00
|
|
|
GtkWidget *image;
|
|
|
|
GdkPixbuf *pixbuf;
|
2003-07-24 21:09:01 +08:00
|
|
|
|
|
|
|
if (is_image)
|
2004-07-31 07:03:45 +08:00
|
|
|
pixbuf = gimp_image_get_thumbnail (any_ID,
|
|
|
|
width, height,
|
|
|
|
GIMP_PIXBUF_SMALL_CHECKS);
|
2003-07-24 21:09:01 +08:00
|
|
|
else
|
2004-07-31 07:03:45 +08:00
|
|
|
pixbuf = gimp_drawable_get_thumbnail (any_ID,
|
|
|
|
width, height,
|
|
|
|
GIMP_PIXBUF_SMALL_CHECKS);
|
2000-05-09 01:45:16 +08:00
|
|
|
|
2004-07-31 07:03:45 +08:00
|
|
|
image = gtk_image_new_from_pixbuf (pixbuf);
|
2000-05-09 01:45:16 +08:00
|
|
|
|
2004-07-31 07:03:45 +08:00
|
|
|
g_object_unref (pixbuf);
|
2003-07-24 21:09:01 +08:00
|
|
|
|
2004-07-31 07:03:45 +08:00
|
|
|
return image;
|
2003-07-24 21:09:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_menu_callback (GtkWidget *widget,
|
2006-04-12 18:53:28 +08:00
|
|
|
gpointer any_ID)
|
2003-07-24 21:09:01 +08:00
|
|
|
{
|
|
|
|
GimpMenuCallback callback;
|
|
|
|
gpointer callback_data;
|
|
|
|
|
|
|
|
callback = (GimpMenuCallback) g_object_get_data (G_OBJECT (widget->parent),
|
|
|
|
"gimp-menu-callback");
|
|
|
|
callback_data = g_object_get_data (G_OBJECT (widget->parent),
|
|
|
|
"gimp-menu-callback-data");
|
|
|
|
|
|
|
|
(* callback) (GPOINTER_TO_INT (any_ID), callback_data);
|
1999-06-24 07:01:14 +08:00
|
|
|
}
|