mirror of https://github.com/GNOME/gimp.git
removed the GWeakNotify stuff again and free the ID arrays after creating
2003-07-24 Michael Natterer <mitch@gimp.org> * libgimp/gimpmenu.c: removed the GWeakNotify stuff again and free the ID arrays after creating the menu. Pass the ID as user_data to the "activate" callback using GINT_TO_POINTER(). Added previews to gimp_image_menu_new(). More cleanup.
This commit is contained in:
parent
f9e1967a50
commit
35966a934d
|
@ -1,3 +1,10 @@
|
||||||
|
2003-07-24 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
|
* libgimp/gimpmenu.c: removed the GWeakNotify stuff again and free
|
||||||
|
the ID arrays after creating the menu. Pass the ID as user_data to
|
||||||
|
the "activate" callback using GINT_TO_POINTER(). Added previews
|
||||||
|
to gimp_image_menu_new(). More cleanup.
|
||||||
|
|
||||||
2003-07-24 Michael Natterer <mitch@gimp.org>
|
2003-07-24 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
* app/core/gimptooloptions.c (gimp_tool_options_serialize):
|
* app/core/gimptooloptions.c (gimp_tool_options_serialize):
|
||||||
|
|
|
@ -45,13 +45,14 @@ static GtkWidget * gimp_menu_make_menu (GimpMenuCallback callback,
|
||||||
static GtkWidget * gimp_menu_add_item (GtkWidget *menu,
|
static GtkWidget * gimp_menu_add_item (GtkWidget *menu,
|
||||||
const gchar *image_name,
|
const gchar *image_name,
|
||||||
const gchar *drawable_name,
|
const gchar *drawable_name,
|
||||||
gint32 *drawable_ID);
|
gint32 any_ID);
|
||||||
static void gimp_menu_callback (GtkWidget *widget,
|
static GtkWidget * gimp_menu_add_none (GtkWidget *menu);
|
||||||
gint32 *id);
|
static GtkWidget * gimp_menu_make_preview (gint32 any_ID,
|
||||||
static void fill_preview_with_thumb (GtkWidget *widget,
|
gboolean is_image,
|
||||||
gint32 drawable_ID,
|
|
||||||
gint width,
|
gint width,
|
||||||
gint height);
|
gint height);
|
||||||
|
static void gimp_menu_callback (GtkWidget *widget,
|
||||||
|
gpointer any_ID);
|
||||||
|
|
||||||
|
|
||||||
/* public functions */
|
/* public functions */
|
||||||
|
@ -63,10 +64,10 @@ gimp_image_menu_new (GimpConstraintFunc constraint,
|
||||||
gint32 active_image)
|
gint32 active_image)
|
||||||
{
|
{
|
||||||
GtkWidget *menu;
|
GtkWidget *menu;
|
||||||
GtkWidget *menuitem;
|
|
||||||
gchar *name;
|
gchar *name;
|
||||||
gchar *label;
|
gchar *label;
|
||||||
gint32 *images;
|
gint32 *images;
|
||||||
|
gint32 image = -1;
|
||||||
gint n_images;
|
gint n_images;
|
||||||
gint i, k;
|
gint i, k;
|
||||||
|
|
||||||
|
@ -83,39 +84,28 @@ gimp_image_menu_new (GimpConstraintFunc constraint,
|
||||||
label = g_strdup_printf ("%s-%d", name, images[i]);
|
label = g_strdup_printf ("%s-%d", name, images[i]);
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
menuitem = gtk_menu_item_new_with_label (label);
|
gimp_menu_add_item (menu, label, NULL, images[i]);
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
||||||
gtk_widget_show (menuitem);
|
|
||||||
|
|
||||||
g_free (label);
|
g_free (label);
|
||||||
|
|
||||||
g_signal_connect (menuitem, "activate",
|
|
||||||
G_CALLBACK (gimp_menu_callback),
|
|
||||||
&images[i]);
|
|
||||||
|
|
||||||
if (images[i] == active_image)
|
if (images[i] == active_image)
|
||||||
|
{
|
||||||
|
image = active_image;
|
||||||
gtk_menu_set_active (GTK_MENU (menu), k);
|
gtk_menu_set_active (GTK_MENU (menu), k);
|
||||||
|
}
|
||||||
|
else if (image == -1)
|
||||||
|
image = images[i];
|
||||||
|
|
||||||
k += 1;
|
k += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k == 0)
|
if (k == 0)
|
||||||
{
|
gimp_menu_add_none (menu);
|
||||||
menuitem = gtk_menu_item_new_with_label (_("None"));
|
|
||||||
gtk_widget_set_sensitive (menuitem, FALSE);
|
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
||||||
gtk_widget_show (menuitem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (images)
|
|
||||||
{
|
|
||||||
if (active_image == -1)
|
|
||||||
active_image = images[0];
|
|
||||||
|
|
||||||
|
if (image != -1)
|
||||||
(* callback) (active_image, data);
|
(* callback) (active_image, data);
|
||||||
|
|
||||||
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, images);
|
g_free (images);
|
||||||
}
|
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +117,6 @@ gimp_layer_menu_new (GimpConstraintFunc constraint,
|
||||||
gint32 active_layer)
|
gint32 active_layer)
|
||||||
{
|
{
|
||||||
GtkWidget *menu;
|
GtkWidget *menu;
|
||||||
GtkWidget *menuitem;
|
|
||||||
gchar *image_label;
|
gchar *image_label;
|
||||||
gint32 *images;
|
gint32 *images;
|
||||||
gint32 *layers;
|
gint32 *layers;
|
||||||
|
@ -157,8 +146,7 @@ gimp_layer_menu_new (GimpConstraintFunc constraint,
|
||||||
if (! constraint || (* constraint) (images[i], layers[j], data))
|
if (! constraint || (* constraint) (images[i], layers[j], data))
|
||||||
{
|
{
|
||||||
name = gimp_layer_get_name (layers[j]);
|
name = gimp_layer_get_name (layers[j]);
|
||||||
menuitem = gimp_menu_add_item (menu, name, image_label,
|
gimp_menu_add_item (menu, image_label, name, layers[j]);
|
||||||
&layers[j]);
|
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
if (layers[j] == active_layer)
|
if (layers[j] == active_layer)
|
||||||
|
@ -173,19 +161,13 @@ gimp_layer_menu_new (GimpConstraintFunc constraint,
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (image_label);
|
g_free (image_label);
|
||||||
|
g_free (layers);
|
||||||
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, layers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (images);
|
g_free (images);
|
||||||
|
|
||||||
if (k == 0)
|
if (k == 0)
|
||||||
{
|
gimp_menu_add_none (menu);
|
||||||
menuitem = gtk_menu_item_new_with_label (_("None"));
|
|
||||||
gtk_widget_set_sensitive (menuitem, FALSE);
|
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
||||||
gtk_widget_show (menuitem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layer != -1)
|
if (layer != -1)
|
||||||
(* callback) (layer, data);
|
(* callback) (layer, data);
|
||||||
|
@ -200,7 +182,6 @@ gimp_channel_menu_new (GimpConstraintFunc constraint,
|
||||||
gint32 active_channel)
|
gint32 active_channel)
|
||||||
{
|
{
|
||||||
GtkWidget *menu;
|
GtkWidget *menu;
|
||||||
GtkWidget *menuitem;
|
|
||||||
gchar *image_label;
|
gchar *image_label;
|
||||||
gint32 *images;
|
gint32 *images;
|
||||||
gint32 *channels;
|
gint32 *channels;
|
||||||
|
@ -232,8 +213,7 @@ gimp_channel_menu_new (GimpConstraintFunc constraint,
|
||||||
if (! constraint || (* constraint) (images[i], channels[j], data))
|
if (! constraint || (* constraint) (images[i], channels[j], data))
|
||||||
{
|
{
|
||||||
name = gimp_channel_get_name (channels[j]);
|
name = gimp_channel_get_name (channels[j]);
|
||||||
menuitem = gimp_menu_add_item (menu, name, image_label,
|
gimp_menu_add_item (menu, image_label, name, channels[j]);
|
||||||
&channels[j]);
|
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
if (channels[j] == active_channel)
|
if (channels[j] == active_channel)
|
||||||
|
@ -248,19 +228,13 @@ gimp_channel_menu_new (GimpConstraintFunc constraint,
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (image_label);
|
g_free (image_label);
|
||||||
|
g_free (channels);
|
||||||
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, channels);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (images);
|
g_free (images);
|
||||||
|
|
||||||
if (k == 0)
|
if (k == 0)
|
||||||
{
|
gimp_menu_add_none (menu);
|
||||||
menuitem = gtk_menu_item_new_with_label (_("None"));
|
|
||||||
gtk_widget_set_sensitive (menuitem, FALSE);
|
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
||||||
gtk_widget_show (menuitem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel != -1)
|
if (channel != -1)
|
||||||
(* callback) (channel, data);
|
(* callback) (channel, data);
|
||||||
|
@ -275,7 +249,6 @@ gimp_drawable_menu_new (GimpConstraintFunc constraint,
|
||||||
gint32 active_drawable)
|
gint32 active_drawable)
|
||||||
{
|
{
|
||||||
GtkWidget *menu;
|
GtkWidget *menu;
|
||||||
GtkWidget *menuitem;
|
|
||||||
gchar *name;
|
gchar *name;
|
||||||
gchar *image_label;
|
gchar *image_label;
|
||||||
gint32 *images;
|
gint32 *images;
|
||||||
|
@ -307,8 +280,7 @@ gimp_drawable_menu_new (GimpConstraintFunc constraint,
|
||||||
if (! constraint || (* constraint) (images[i], layers[j], data))
|
if (! constraint || (* constraint) (images[i], layers[j], data))
|
||||||
{
|
{
|
||||||
name = gimp_layer_get_name (layers[j]);
|
name = gimp_layer_get_name (layers[j]);
|
||||||
menuitem = gimp_menu_add_item (menu, name, image_label,
|
gimp_menu_add_item (menu, image_label, name, layers[j]);
|
||||||
&layers[j]);
|
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
if (layers[j] == active_drawable)
|
if (layers[j] == active_drawable)
|
||||||
|
@ -326,8 +298,7 @@ gimp_drawable_menu_new (GimpConstraintFunc constraint,
|
||||||
if (! constraint || (* constraint) (images[i], channels[j], data))
|
if (! constraint || (* constraint) (images[i], channels[j], data))
|
||||||
{
|
{
|
||||||
name = gimp_channel_get_name (channels[j]);
|
name = gimp_channel_get_name (channels[j]);
|
||||||
menuitem = gimp_menu_add_item (menu, name, image_label,
|
gimp_menu_add_item (menu, image_label, name, channels[j]);
|
||||||
&channels[j]);
|
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
if (channels[j] == active_drawable)
|
if (channels[j] == active_drawable)
|
||||||
|
@ -342,20 +313,14 @@ gimp_drawable_menu_new (GimpConstraintFunc constraint,
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (image_label);
|
g_free (image_label);
|
||||||
|
g_free (layers);
|
||||||
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, layers);
|
g_free (channels);
|
||||||
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, channels);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (images);
|
g_free (images);
|
||||||
|
|
||||||
if (k == 0)
|
if (k == 0)
|
||||||
{
|
gimp_menu_add_none (menu);
|
||||||
menuitem = gtk_menu_item_new_with_label (_("None"));
|
|
||||||
gtk_widget_set_sensitive (menuitem, FALSE);
|
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
||||||
gtk_widget_show (menuitem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (drawable != -1)
|
if (drawable != -1)
|
||||||
(* callback) (drawable, data);
|
(* callback) (drawable, data);
|
||||||
|
@ -383,16 +348,19 @@ static GtkWidget *
|
||||||
gimp_menu_add_item (GtkWidget *menu,
|
gimp_menu_add_item (GtkWidget *menu,
|
||||||
const gchar *image_name,
|
const gchar *image_name,
|
||||||
const gchar *drawable_name,
|
const gchar *drawable_name,
|
||||||
gint32 *drawable_ID)
|
gint32 any_ID)
|
||||||
{
|
{
|
||||||
GtkWidget *menuitem;
|
GtkWidget *menuitem;
|
||||||
GtkWidget *hbox;
|
GtkWidget *hbox;
|
||||||
GtkWidget *vbox;
|
GtkWidget *vbox;
|
||||||
GtkWidget *wcolor_box;
|
GtkWidget *preview;
|
||||||
GtkWidget *wlabel;
|
GtkWidget *label;
|
||||||
gchar *label;
|
gchar *str;
|
||||||
|
|
||||||
label = g_strdup_printf ("%s/%s", image_name, drawable_name);
|
if (drawable_name)
|
||||||
|
str = g_strdup_printf ("%s/%s-%d", image_name, drawable_name, any_ID);
|
||||||
|
else
|
||||||
|
str = g_strdup (image_name);
|
||||||
|
|
||||||
menuitem = gtk_menu_item_new ();
|
menuitem = gtk_menu_item_new ();
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
||||||
|
@ -400,7 +368,7 @@ gimp_menu_add_item (GtkWidget *menu,
|
||||||
|
|
||||||
g_signal_connect (menuitem, "activate",
|
g_signal_connect (menuitem, "activate",
|
||||||
G_CALLBACK (gimp_menu_callback),
|
G_CALLBACK (gimp_menu_callback),
|
||||||
drawable_ID);
|
GINT_TO_POINTER (any_ID));
|
||||||
|
|
||||||
hbox = gtk_hbox_new (FALSE, 4);
|
hbox = gtk_hbox_new (FALSE, 4);
|
||||||
gtk_container_add (GTK_CONTAINER (menuitem), hbox);
|
gtk_container_add (GTK_CONTAINER (menuitem), hbox);
|
||||||
|
@ -410,50 +378,41 @@ gimp_menu_add_item (GtkWidget *menu,
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
|
||||||
gtk_widget_show (vbox);
|
gtk_widget_show (vbox);
|
||||||
|
|
||||||
wcolor_box = gtk_preview_new (GTK_PREVIEW_COLOR);
|
preview = gimp_menu_make_preview (any_ID, drawable_name == NULL,
|
||||||
gtk_preview_set_dither (GTK_PREVIEW (wcolor_box),
|
|
||||||
GDK_RGB_DITHER_MAX);
|
|
||||||
gtk_widget_set_size_request (GTK_WIDGET (wcolor_box),
|
|
||||||
MENU_THUMBNAIL_WIDTH,
|
MENU_THUMBNAIL_WIDTH,
|
||||||
MENU_THUMBNAIL_HEIGHT);
|
MENU_THUMBNAIL_HEIGHT);
|
||||||
|
gtk_container_add (GTK_CONTAINER (vbox), preview);
|
||||||
|
gtk_widget_show (preview);
|
||||||
|
|
||||||
fill_preview_with_thumb (wcolor_box, *drawable_ID,
|
label = gtk_label_new (str);
|
||||||
MENU_THUMBNAIL_WIDTH,
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
||||||
MENU_THUMBNAIL_HEIGHT);
|
gtk_widget_show (label);
|
||||||
|
|
||||||
gtk_container_add (GTK_CONTAINER (vbox), wcolor_box);
|
g_free (str);
|
||||||
gtk_widget_show (wcolor_box);
|
|
||||||
|
|
||||||
wlabel = gtk_label_new (label);
|
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), wlabel, FALSE, FALSE, 0);
|
|
||||||
gtk_widget_show (wlabel);
|
|
||||||
|
|
||||||
g_free (label);
|
|
||||||
|
|
||||||
return menuitem;
|
return menuitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static GtkWidget *
|
||||||
gimp_menu_callback (GtkWidget *widget,
|
gimp_menu_add_none (GtkWidget *menu)
|
||||||
gint32 *id)
|
|
||||||
{
|
{
|
||||||
GimpMenuCallback callback;
|
GtkWidget *menuitem;
|
||||||
gpointer callback_data;
|
|
||||||
|
|
||||||
callback = (GimpMenuCallback) g_object_get_data (G_OBJECT (widget->parent),
|
menuitem = gtk_menu_item_new_with_label (_("None"));
|
||||||
"gimp-menu-callback");
|
gtk_widget_set_sensitive (menuitem, FALSE);
|
||||||
callback_data = g_object_get_data (G_OBJECT (widget->parent),
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
||||||
"gimp-menu-callback-data");
|
gtk_widget_show (menuitem);
|
||||||
|
|
||||||
(* callback) (*id, callback_data);
|
return menuitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static GtkWidget *
|
||||||
fill_preview_with_thumb (GtkWidget *widget,
|
gimp_menu_make_preview (gint32 any_ID,
|
||||||
gint32 drawable_ID,
|
gboolean is_image,
|
||||||
gint width,
|
gint width,
|
||||||
gint height)
|
gint height)
|
||||||
{
|
{
|
||||||
|
GtkWidget *preview;
|
||||||
guchar *preview_data;
|
guchar *preview_data;
|
||||||
gint bpp;
|
gint bpp;
|
||||||
gint x, y;
|
gint x, y;
|
||||||
|
@ -464,10 +423,18 @@ fill_preview_with_thumb (GtkWidget *widget,
|
||||||
|
|
||||||
bpp = 0; /* Only returned */
|
bpp = 0; /* Only returned */
|
||||||
|
|
||||||
preview_data = gimp_drawable_get_thumbnail_data (drawable_ID,
|
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||||
|
gtk_preview_set_dither (GTK_PREVIEW (preview), GDK_RGB_DITHER_MAX);
|
||||||
|
gtk_widget_set_size_request (GTK_WIDGET (preview), width, height);
|
||||||
|
|
||||||
|
if (is_image)
|
||||||
|
preview_data = gimp_image_get_thumbnail_data (any_ID,
|
||||||
|
&width, &height, &bpp);
|
||||||
|
else
|
||||||
|
preview_data = gimp_drawable_get_thumbnail_data (any_ID,
|
||||||
&width, &height, &bpp);
|
&width, &height, &bpp);
|
||||||
|
|
||||||
gtk_preview_size (GTK_PREVIEW (widget), width, height);
|
gtk_preview_size (GTK_PREVIEW (preview), width, height);
|
||||||
|
|
||||||
even = g_malloc (width * 3);
|
even = g_malloc (width * 3);
|
||||||
odd = g_malloc (width * 3);
|
odd = g_malloc (width * 3);
|
||||||
|
@ -525,9 +492,9 @@ fill_preview_with_thumb (GtkWidget *widget,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((y / GIMP_CHECK_SIZE_SM) & 1)
|
if ((y / GIMP_CHECK_SIZE_SM) & 1)
|
||||||
gtk_preview_draw_row (GTK_PREVIEW (widget), odd, 0, y, width);
|
gtk_preview_draw_row (GTK_PREVIEW (preview), odd, 0, y, width);
|
||||||
else
|
else
|
||||||
gtk_preview_draw_row (GTK_PREVIEW (widget), even, 0, y, width);
|
gtk_preview_draw_row (GTK_PREVIEW (preview), even, 0, y, width);
|
||||||
|
|
||||||
src += width * bpp;
|
src += width * bpp;
|
||||||
}
|
}
|
||||||
|
@ -535,4 +502,21 @@ fill_preview_with_thumb (GtkWidget *widget,
|
||||||
g_free (preview_data);
|
g_free (preview_data);
|
||||||
g_free (even);
|
g_free (even);
|
||||||
g_free (odd);
|
g_free (odd);
|
||||||
|
|
||||||
|
return preview;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gimp_menu_callback (GtkWidget *widget,
|
||||||
|
gpointer any_ID)
|
||||||
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue