[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: newbie question
- From: Thomas Mailund <mailund mailund dk>
- To: GTK+ App devel list <gtk-app-devel-list gnome org>
- Subject: Re: newbie question
- Date: 30 Aug 2001 20:08:04 +0930
On Thu, 2001-08-30 at 20:45, christophe barbé wrote:
> I would like to attach a function to a click on a gtk pixmap or a gtk vbox.
> I've tried various code and finally my conclusion is that it's impossible.
> This seem's to be because these widgets don't own a (X) window. In my
> (limited) understanding these are drawn directly on there parent window.
to get events without an X window you use GtkEventBox. I've attached an
example. (In the example I use gdkpixbuf, 'cause I had some code lying
around, but you can use whatever you need).
/mailund
--
If an animal is caught in a trap it will chew its leg off to
escape. If a human is caught in a trap it will wait and kill the
trapper and eliminate a threat to its kind.
-- Frank Herbert
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
void
clicked (void)
{
g_print ("clicked\n");
}
int
main (int argc, char *argv[])
{
GtkWidget *win;
GdkPixbuf *img;
GdkPixmap *pixmap;
GdkBitmap *mask;
GtkWidget *image;
GtkWidget *event_box;
gtk_init (&argc, &argv);
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
img = gdk_pixbuf_new_from_file ("./pr0n.jpg");
gdk_pixbuf_render_pixmap_and_mask (img, &pixmap, &mask, 0);
image = gtk_pixmap_new (pixmap, mask);
event_box = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (win), event_box);
gtk_container_add (GTK_CONTAINER (event_box), image);
gtk_signal_connect(GTK_OBJECT(event_box), "button_press_event",
GTK_SIGNAL_FUNC (clicked), NULL);
gtk_widget_add_events(event_box, GDK_BUTTON_PRESS_MASK);
gtk_widget_show_all (win);
gtk_main ();
return 0;
}
PGP signature
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]