imlib/gtk/gtk_object_set_data -> invalid cast from gchar to ...




Hi,

this problem is breaking my brains all afternoon already... 
I've been a good girl, I checked the FAQ, I checked the archive
of this and other mailing-lists as much as I could, yet I couldn't
get my problem solved. So if one of you out there... 

okay... here's the problem:

my goal: I'm writing a GUI for something, where the user can
push on a button, and have some graphical view on, in my case, 
an aquarium (yeah, with fishes around and stuff). That user is
allowed to open several such views. 

my first attempt: 
Using imlib, gtk, gdk, and having as global variables
a pixmap (GdkPixmap), a mask (GdkPixmap) and an image (GdkImlibImage).
Due of course to the fact that these entities are global
variables, a user could only open one view, or else the
application would crash (which is in my opinion quite logical), 
but for one single view, the program worked.

yet I want to be able to manipulate several views... 
so here goes my second attempt:
I define a struct which contains 3 fields (2 pixmaps, and an image),
attach the final data to my widget (gtk_object_set_data), 
rewrite a bit my code... but of course, it doesn't work.

here's the piece of code:

/*** aquarium.h ***/
/*
 * interface for creating an area where the fishes are going to
 * be shown to the user 
 */

#ifndef AQUARIUM
#define AQUARIUM

#include <gtk/gtk.h>
#include <gdk_imlib.h>

GtkWidget *make_a_cute_aquarium();
void show_a_cute_aquarium( GtkWidget *aq);

#endif

/*** aquarium.c ***/

#include "aquarium.h"

/* just use the same background for every aquarium */
#define BACKGROUNDIMG "boot.xpm"

typedef struct _ImPixMask {
	GdkImlibImage 	*im;
	GdkPixmap     	*pixmap;
	GdkPixmap	*mask;
} ImPixMask;

/* I want that the image gets rescaled whenever the user resizes 
 * the window, so I need handlers for the configure_event, and 
 * expose_event
 */
static gint configure_event (GtkWidget *widget, GdkEventConfigure *event,
		gpointer data)
{
	ImPixMask *impixmask;
	gint w,h;

	g_print("we're configuring...\n");
	impixmask = 
		(ImPixMask *) gtk_object_get_data( GTK_OBJECT (widget),
						   "impixmask");
	/** free background */
	gdk_imlib_free_pixmap(impixmask->pixmap);

	/** rerender the image */
	w = widget->allocation.width;
	h = widget->allocation.height;

	gdk_imlib_render(impixmask->im,w,h);
	impixmask->pixmap = gdk_imlib_move_image(impixmask->im);
	impixmask->mask = gdk_imlib_move_mask(impixmask->im);
	
	return TRUE;
}

gint expose_event ( GtkWidget *widget, GdkEventExpose *event,
		gpointer data)
{
	ImPixMask *impixmask;
	g_print("we're exposing....\n");
	impixmask = 
		(ImPixMask *) gtk_object_get_data( GTK_OBJECT (widget),
						   "impixmask");
	gdk_window_clear( widget->window);
	gdk_window_set_back_pixmap( widget->window, impixmask->pixmap, 0);
	gdk_window_shape_combine_mask( widget->window, impixmask->mask, 0, 0);

	return FALSE;
}


GtkWidget *make_a_cute_aquarium()
{
	GtkWidget *aq; 
	aq = gtk_drawing_area_new();
	return(aq);
}

void show_a_cute_aquarium(GtkWidget *aq)
{
	char *image_file = BACKGROUNDIMG;
	char c;
	gint w,h;
	ImPixMask *impixmask;
	GdkImlibImage *i;
	GdkPixmap *p, *m;

	/* loading all image-related information */

	g_print("loading the image\n");
	i = gdk_imlib_load_image( image_file );
	w = i->rgb_width;
	h = i->rgb_height;

	g_print("resize the aquarium\n");
	gtk_drawing_area_size (GTK_DRAWING_AREA (aq), w, h);
	gtk_widget_realize(aq);

	g_print("associating the data\n");
	gtk_object_set_data( GTK_OBJECT (aq), "impixmask", (gpointer)impixmask);
	gtk_widget_set_app_paintable(GTK_WIDGET (aq), TRUE);

	
	g_print("connect the signals\n");
	gtk_signal_connect (GTK_OBJECT (aq), "expose_event",
			GTK_SIGNAL_FUNC (expose_event), NULL);

	g_print("expose_event connected\n");

	gtk_signal_connect (GTK_OBJECT (aq), "configure_event",
			GTK_SIGNAL_FUNC (configure_event), NULL);

	g_print("rendering the image, and creating the pixmap/mask\n");
	gdk_imlib_render(i, w, h); 
	p = gdk_imlib_move_image(i);
	m = gdk_imlib_move_mask(i);

	g_print("putting it all together in the ImPixMask structure\n");
	impixmask->im = i;
	impixmask->pixmap = p;
	impixmask->mask = m;

	g_print("send the image to the aquarium\n");

	gdk_window_set_back_pixmap( aq->window, p, 0);
	gdk_window_shape_combine_mask( aq->window, m, 0, 0);

	g_print("show the background\n");
	gdk_window_show(aq->window); 
	g_print("show the widget\n");
	gtk_widget_show( GTK_WIDGET (aq));

}


Okay, when running, this is what I get when I push the button
to open an aquarium-view:

------
loading the image
resize the aquarium
associating the data
connect the signals
expose_event connected
rendering the image, and creating the pixmap/mask
putting it all together in the ImPixMask structure
send the image to the aquarium
show the background
show the widget

Gtk-WARNING **: invalid cast from `gchar' to `GtkWidget'

Gtk-CRITICAL **: file gtkwidget.c: line 1435 (gtk_widget_show): assertion `GTK_IS_WIDGET (widget)' failed.

Gtk-WARNING **: invalid cast from `gchar' to `GtkObject'

Gtk-WARNING **: invalid cast from `gchar' to `GtkObject'

Gtk-WARNING **: invalid cast from `gchar' to `GtkObject'

Gtk-CRITICAL **: file gtkwidget.c: line 2679 (gtk_widget_event): assertion `GTK_IS_WIDGET (widget)' failed.

Gtk-WARNING **: invalid cast from `gchar' to `GtkObject'
...

------

Does anybody have a clue??? 'cause I'm simply stuck...

many thanks in advance,

Nancy Mazur

/* Nancy Mazur -- Phd student @ K.U.Leuven, dept. Computer Science
 * nancy.mazur@cs.kuleuven.ac.be 
 */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]