Re: Send mouse button press event to widget??




I am creating a virtual cursor on a web page and want to simulate the left
click of the mouse button
when the user presses the enter button.
So I tried even using the gdk_event_put on the global window itself,assuming
the event would find it's 
way to the control under the cursor.
The gdk_event_put has not been successful,so what is the way to achieve
this?
--Mayur.


David NeÄas (Yeti)-2 wrote:

On Thu, Aug 30, 2007 at 03:37:04AM -0700, eminemence wrote:

Am a newbie to linux gtk programming.I want trying to send the mouse
button
press event to my widget and so I tried this code:
Code:
###########################################
         guint signalid = g_signal_new("button_press_event",
                                 G_TYPE_FUNDAMENTAL(0),
                                 G_SIGNAL_RUN_FIRST,
                                 NULL,
                                 NULL,
                                 NULL,
                                 NULL,
                                 G_TYPE_NONE,0);
         g_signal_emit(GTK_OBJECT(gPage),signalid,0);
###########################################
Can someone tell me what is wrong out there?

Several things:

1) g_signal_new() creates (registers) a new signal for
   a class -- a new `type' of signal.  This is not what you
   want, you want to emit an existing signal
   "button-press-event" (though see below).

2) The g_signal_new() arguments are bogus, for instance if
   you actually registered a new signal for GtkWidget, you
   would pass GTK_TYPE_WIDGET, not G_TYPE_FUNDAMENTAL(0)
   (which makes little sense) as the instance type, but
   since you don't want to register a new signal, I will
   leave this.

3) Signal is emitted with g_signal_emit() -- or rather
   g_signal_emit_by_name() if done by code outside the
   class:

       g_signal_emit_by_name(button, "clicked");

   (in practice a method to emit this signal is defined for
   most signal one wants to emit in application code, so
   you would use gtk_button_clicked() here).

4) Events are special and sending events is done by
   a different functions than normal signal emission:
   gtk_main_do_event() or gtk_widget_event().  First you
   synthetize the event by creating it with gdk_event_new()
   and filling the fields, then send it and free with
   gdk_event_free().

Now, forget all this because in almost all cases you think
you need to send a synthetic an event to a widget, a better
solution exists.  So, tell what you want to achieve.

Yeti

--
http://gwyddion.net/
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



-- 
View this message in context: 
http://www.nabble.com/Send-mouse-button-press-event-to-widget---tf4353330.html#a12406136
Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com.




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