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:
Michael Natterer 2003-07-24 13:09:01 +00:00 committed by Michael Natterer
parent f9e1967a50
commit 35966a934d
2 changed files with 106 additions and 115 deletions

View File

@ -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>
* app/core/gimptooloptions.c (gimp_tool_options_serialize):

View File

@ -45,13 +45,14 @@ static GtkWidget * gimp_menu_make_menu (GimpMenuCallback callback,
static GtkWidget * gimp_menu_add_item (GtkWidget *menu,
const gchar *image_name,
const gchar *drawable_name,
gint32 *drawable_ID);
static void gimp_menu_callback (GtkWidget *widget,
gint32 *id);
static void fill_preview_with_thumb (GtkWidget *widget,
gint32 drawable_ID,
gint32 any_ID);
static GtkWidget * gimp_menu_add_none (GtkWidget *menu);
static GtkWidget * gimp_menu_make_preview (gint32 any_ID,
gboolean is_image,
gint width,
gint height);
static void gimp_menu_callback (GtkWidget *widget,
gpointer any_ID);
/* public functions */
@ -63,10 +64,10 @@ gimp_image_menu_new (GimpConstraintFunc constraint,
gint32 active_image)
{
GtkWidget *menu;
GtkWidget *menuitem;
gchar *name;
gchar *label;
gint32 *images;
gint32 image = -1;
gint n_images;
gint i, k;
@ -83,39 +84,28 @@ gimp_image_menu_new (GimpConstraintFunc constraint,
label = g_strdup_printf ("%s-%d", name, images[i]);
g_free (name);
menuitem = gtk_menu_item_new_with_label (label);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
gtk_widget_show (menuitem);
gimp_menu_add_item (menu, label, NULL, images[i]);
g_free (label);
g_signal_connect (menuitem, "activate",
G_CALLBACK (gimp_menu_callback),
&images[i]);
g_free (label);
if (images[i] == active_image)
gtk_menu_set_active (GTK_MENU (menu), k);
{
image = active_image;
gtk_menu_set_active (GTK_MENU (menu), k);
}
else if (image == -1)
image = images[i];
k += 1;
}
if (k == 0)
{
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);
}
gimp_menu_add_none (menu);
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;
}
@ -127,7 +117,6 @@ gimp_layer_menu_new (GimpConstraintFunc constraint,
gint32 active_layer)
{
GtkWidget *menu;
GtkWidget *menuitem;
gchar *image_label;
gint32 *images;
gint32 *layers;
@ -157,8 +146,7 @@ gimp_layer_menu_new (GimpConstraintFunc constraint,
if (! constraint || (* constraint) (images[i], layers[j], data))
{
name = gimp_layer_get_name (layers[j]);
menuitem = gimp_menu_add_item (menu, name, image_label,
&layers[j]);
gimp_menu_add_item (menu, image_label, name, layers[j]);
g_free (name);
if (layers[j] == active_layer)
@ -173,19 +161,13 @@ gimp_layer_menu_new (GimpConstraintFunc constraint,
}
g_free (image_label);
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, layers);
g_free (layers);
}
g_free (images);
if (k == 0)
{
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);
}
gimp_menu_add_none (menu);
if (layer != -1)
(* callback) (layer, data);
@ -200,7 +182,6 @@ gimp_channel_menu_new (GimpConstraintFunc constraint,
gint32 active_channel)
{
GtkWidget *menu;
GtkWidget *menuitem;
gchar *image_label;
gint32 *images;
gint32 *channels;
@ -232,8 +213,7 @@ gimp_channel_menu_new (GimpConstraintFunc constraint,
if (! constraint || (* constraint) (images[i], channels[j], data))
{
name = gimp_channel_get_name (channels[j]);
menuitem = gimp_menu_add_item (menu, name, image_label,
&channels[j]);
gimp_menu_add_item (menu, image_label, name, channels[j]);
g_free (name);
if (channels[j] == active_channel)
@ -248,19 +228,13 @@ gimp_channel_menu_new (GimpConstraintFunc constraint,
}
g_free (image_label);
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, channels);
g_free (channels);
}
g_free (images);
if (k == 0)
{
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);
}
gimp_menu_add_none (menu);
if (channel != -1)
(* callback) (channel, data);
@ -275,7 +249,6 @@ gimp_drawable_menu_new (GimpConstraintFunc constraint,
gint32 active_drawable)
{
GtkWidget *menu;
GtkWidget *menuitem;
gchar *name;
gchar *image_label;
gint32 *images;
@ -307,8 +280,7 @@ gimp_drawable_menu_new (GimpConstraintFunc constraint,
if (! constraint || (* constraint) (images[i], layers[j], data))
{
name = gimp_layer_get_name (layers[j]);
menuitem = gimp_menu_add_item (menu, name, image_label,
&layers[j]);
gimp_menu_add_item (menu, image_label, name, layers[j]);
g_free (name);
if (layers[j] == active_drawable)
@ -326,8 +298,7 @@ gimp_drawable_menu_new (GimpConstraintFunc constraint,
if (! constraint || (* constraint) (images[i], channels[j], data))
{
name = gimp_channel_get_name (channels[j]);
menuitem = gimp_menu_add_item (menu, name, image_label,
&channels[j]);
gimp_menu_add_item (menu, image_label, name, channels[j]);
g_free (name);
if (channels[j] == active_drawable)
@ -342,20 +313,14 @@ gimp_drawable_menu_new (GimpConstraintFunc constraint,
}
g_free (image_label);
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, layers);
g_object_weak_ref (G_OBJECT (menu), (GWeakNotify) g_free, channels);
g_free (layers);
g_free (channels);
}
g_free (images);
if (k == 0)
{
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);
}
gimp_menu_add_none (menu);
if (drawable != -1)
(* callback) (drawable, data);
@ -383,16 +348,19 @@ static GtkWidget *
gimp_menu_add_item (GtkWidget *menu,
const gchar *image_name,
const gchar *drawable_name,
gint32 *drawable_ID)
gint32 any_ID)
{
GtkWidget *menuitem;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *wcolor_box;
GtkWidget *wlabel;
gchar *label;
GtkWidget *preview;
GtkWidget *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 ();
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_CALLBACK (gimp_menu_callback),
drawable_ID);
GINT_TO_POINTER (any_ID));
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (menuitem), hbox);
@ -410,64 +378,63 @@ gimp_menu_add_item (GtkWidget *menu,
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
gtk_widget_show (vbox);
wcolor_box = gtk_preview_new (GTK_PREVIEW_COLOR);
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_HEIGHT);
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);
fill_preview_with_thumb (wcolor_box, *drawable_ID,
MENU_THUMBNAIL_WIDTH,
MENU_THUMBNAIL_HEIGHT);
label = gtk_label_new (str);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
gtk_container_add (GTK_CONTAINER (vbox), wcolor_box);
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);
g_free (str);
return menuitem;
}
static void
gimp_menu_callback (GtkWidget *widget,
gint32 *id)
static GtkWidget *
gimp_menu_add_none (GtkWidget *menu)
{
GimpMenuCallback callback;
gpointer callback_data;
GtkWidget *menuitem;
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");
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);
(* callback) (*id, callback_data);
return menuitem;
}
static void
fill_preview_with_thumb (GtkWidget *widget,
gint32 drawable_ID,
gint width,
gint height)
static GtkWidget *
gimp_menu_make_preview (gint32 any_ID,
gboolean is_image,
gint width,
gint height)
{
guchar *preview_data;
gint bpp;
gint x, y;
guchar *src;
gdouble r, g, b, a;
gdouble c0, c1;
guchar *p0, *p1, *even, *odd;
GtkWidget *preview;
guchar *preview_data;
gint bpp;
gint x, y;
guchar *src;
gdouble r, g, b, a;
gdouble c0, c1;
guchar *p0, *p1, *even, *odd;
bpp = 0; /* Only returned */
preview_data = gimp_drawable_get_thumbnail_data (drawable_ID,
&width, &height, &bpp);
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);
gtk_preview_size (GTK_PREVIEW (widget), 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);
gtk_preview_size (GTK_PREVIEW (preview), width, height);
even = 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)
gtk_preview_draw_row (GTK_PREVIEW (widget), odd, 0, y, width);
gtk_preview_draw_row (GTK_PREVIEW (preview), odd, 0, y, width);
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;
}
@ -535,4 +502,21 @@ fill_preview_with_thumb (GtkWidget *widget,
g_free (preview_data);
g_free (even);
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);
}