Re: connecting callback to click on GtkImage



On Thu, 22 Apr 2004, Thomas Deschepper wrote:
How can I do this? To which parentwidget will I have to cast??
Hello Thomas!
When you look at the API-reference of GtkImage you can see the object
hierarchy:
 GObject
   +----GtkObject
         +----GtkWidget
               +----GtkMisc
                     +----GtkImage
This means that GtkImage has inherited all properties and signals from
GtkMisc, which itself inherited everything from GtkWidget and so on. That
means you can use e.g. all signals from GtkWidget.
When you now look at the signal list of GtkWidget you will see
"button-press-event"
            gboolean    user_function      (GtkWidget *widget,
                                            GdkEventButton *event,
                                            gpointer user_data);
and

"button-release-event"
            gboolean    user_function      (GtkWidget *widget,
                                            GdkEventButton *event,
                                            gpointer user_data);

There is no "clicked" for GtkWidget, but "button-press-event" will be
emited at the moment you press the mouse button and "button-release-event"
when you release it. Proably connecting to "button-press-event" is
what you want. To make a signal work you may also need to enable it for
your widget.

// create the image widget
GtkWidget *pImage = gtk_image_new();
// enable signals
// this must be called BEFORE you show or realize the widget!
gtk_widget_add_events(pImage, GDK_BUTTON_PRESS_MASK |
  GDK_BUTTON_RELEASE_MASK);
// connect a signal handler
g_signal_connect(G_OBJECT(pImage), "button-press-event",
  G_CALLBACK(CbButtonPressEvent), 0);

Regards,
                     Peter
-- 
====================================================================
Peter Krüger

applied software solutions (appss) GmbH
Sandtorstr. 23
D-39106 Magdeburg
Germany

Phone:  +49-(0)391-54486-19388
Fax:    +49-(0)391-54486-19222
email:  krueger appss de
URL:    http://www.appss.de/

Managing Director: Uwe Hess, Dietmar Schäfer
Register: HRB12386, AG Magdeburg

"Virtual business becomes reality!"

This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail. Any
unauthorised copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
====================================================================




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