problem with callback
Thanks for advice Richard Boaz But only I have a problem with your solution, the user must have the mouse all time inside of the drawing area if he want interact with the drawing area, and if he want interact with the menu he need to move the mouse or use the keyboard for interact with the menu. But I need that the user can interact with the drawing area only with selected the drawing area Without the mouse are inside of drawing area, Bucause at same time that he may interact with the window that contains the drawing area. And if I use the function for block the signal have the problem of that I can't select, copy, paste the text. --- Richard Boaz <[EMAIL PROTECTED]> escribió: > you have gotten your panties into a serious twist. > > start over: > > when wanting to receive key press events in a > drawing area, you must do > all of the following: > > 1. set up the drawing area to receive key press > and/or release events. > 2. set up the drawing area to receive enter and > leave notify events. > 3. when receiving an enter notify event, you must > grab focus of the > drawing area and hold it until you receive the leave > notify event, and > then let it go! > > so, at creation of the drawing area: > > // connect the signals, at least: > g_signal_connect (da, "key_press_event", G_CALLBACK > (keyEvent), NULL); > g_signal_connect (da, "key_release_event", > G_CALLBACK (keyEvent), NULL); > g_signal_connect (da, "enter_notify_event", > G_CALLBACK (grabFocus), NULL); > g_signal_connect (da, "leave_notify_event", > G_CALLBACK (grabFocus), NULL); > > // set up the events to be received by the drawing > area, at least: > gtk_widget_set_events (da, gtk_widget_get_events > (da) > | GDK_LEAVE_NOTIFY_MASK > | GDK_ENTER_NOTIFY_MASK > | GDK_KEY_PRESS_MASK > | GDK_KEY_RELEASE_MASK); > > // define you grabFocus() callback > gboolean grabFocus(GtkWidget *widget, GdkEvent > *event, gpointer nil) > { // we must grab the focus when mouse enters to > receive key events > switch(event->type) > { > case GDK_ENTER_NOTIFY: > gtk_grab_add(GTK_WIDGET (widget)); > break; > case GDK_LEAVE_NOTIFY: > gtk_grab_remove(GTK_WIDGET (widget)); > break; > default: > break; > } > return TRUE; > } > > do it like this and when the mouse is inside the > drawing are, the drawing > are will receive all keyboard events. when the > mouse is outside the > drawing area, the entry area assigned the current > focus will receive the > keyboard events. clicking inside an entry area will > always assign focus > to that entry area. > > to answer your other question, g_signal_connect() > returns the signal > handler id you are looking for. save it when > creating the signal callback > and blocking and unblocking is easily done. > > richard > > ¡Capacidad ilimitada de almacenamiento en tu correo! No te preocupes más por el espacio de tu cuenta con Correo Yahoo!: http://correo.yahoo.com.mx/ ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
problem with callback
you have gotten your panties into a serious twist. start over: when wanting to receive key press events in a drawing area, you must do all of the following: 1. set up the drawing area to receive key press and/or release events. 2. set up the drawing area to receive enter and leave notify events. 3. when receiving an enter notify event, you must grab focus of the drawing area and hold it until you receive the leave notify event, and then let it go! so, at creation of the drawing area: // connect the signals, at least: g_signal_connect (da, "key_press_event", G_CALLBACK (keyEvent), NULL); g_signal_connect (da, "key_release_event", G_CALLBACK (keyEvent), NULL); g_signal_connect (da, "enter_notify_event", G_CALLBACK (grabFocus), NULL); g_signal_connect (da, "leave_notify_event", G_CALLBACK (grabFocus), NULL); // set up the events to be received by the drawing area, at least: gtk_widget_set_events (da, gtk_widget_get_events (da) | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); // define you grabFocus() callback gboolean grabFocus(GtkWidget *widget, GdkEvent *event, gpointer nil) { // we must grab the focus when mouse enters to receive key events switch(event->type) { case GDK_ENTER_NOTIFY: gtk_grab_add(GTK_WIDGET (widget)); break; case GDK_LEAVE_NOTIFY: gtk_grab_remove(GTK_WIDGET (widget)); break; default: break; } return TRUE; } do it like this and when the mouse is inside the drawing are, the drawing are will receive all keyboard events. when the mouse is outside the drawing area, the entry area assigned the current focus will receive the keyboard events. clicking inside an entry area will always assign focus to that entry area. to answer your other question, g_signal_connect() returns the signal handler id you are looking for. save it when creating the signal callback and blocking and unblocking is easily done. richard ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
problem with callback
Hello again I still have the same problem >Hello again >I am making a window that has a menu, two drawing_area > and a GtkEntry > > I added the following events (GDK_BUTTON1_MOTION_MASK, > GDK_BUTTON2_MOTION_MASK, GDK_BUTTON_PRESS_MASK, > GDK_VISIBILITY_NOTIFY_MASK) to the two drawing_area, > and the respective callback, but the problem is that > when I press a any key, the Gtkentry and the two > drawing_are receive the signal, then call the function > callback of the two drawing_area and writes the > character in the Gtkentry. > > My question: > > how can I do for that when I press a key, The signal > will be received only by selected widget, a > drawing_area or the gtkEntry? I used the function gtk_widget_grab_focus () but does not work, because it function only put focus in the widget selected, but the others widget also receive the signal. But I already solve part of problem, I use the event "button_press_event" of each drawing_area for disable the GtkEntry with gtk_entry_set_editable() when I select one of the drawing_area, But even the two drawing_area receive the signal "key_press_event". Then I try to block the callback of "key_press_event" of each drawing_area with g_signal_handlers_block_by_func(), but does not work, and with the function g_signal_handler_block I had problem because I don't know as obtain the handler_id. now I have 3 question. how can I obtain the handler_id for the function g_signal_handler_block? Is there other way to prevent that the drawing_area receive the signal key_press_event? The problem when I use the function gtk_entry_set_editable() for disable the GtkEntry is that for enable the GtkEntry I have to enable the gtkEntry when I select the widget, then I connect the signal "button_press_event" with GtkEntry and in this callback enable the GtkEntry, but now I can't select text of GtkEntry because I connect the event "key_press_event" with the GtkEntry, how can I enable the opcion of select copy and paste of GtkEntry after of connect this signal? ¡Capacidad ilimitada de almacenamiento en tu correo! No te preocupes más por el espacio de tu cuenta con Correo Yahoo!: http://correo.yahoo.com.mx/ ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: problem with callback
did you try this? http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-grab-focus 2008/3/20, Moises <[EMAIL PROTECTED]>: > Hello again > > I am making a window that has a menu, two drawing_area > and a GtkEntry > > I added the following events (GDK_BUTTON1_MOTION_MASK, > GDK_BUTTON2_MOTION_MASK, GDK_BUTTON_PRESS_MASK, > GDK_VISIBILITY_NOTIFY_MASK) to the two drawing_area, > and the respective callback, but the problem is that > when I press a any key, the Gtkentry and the two > drawing_are receive the signal, then call the function > callback of the two drawing_area and writes the > character in the Gtkentry. > > My question: > > how can I do for that when I press a key, The signal > will be received only by selected widget, a > drawing_area or the gtkEntry? > > > > > ¡Capacidad ilimitada de almacenamiento en tu correo! > No te preocupes más por el espacio de tu cuenta con Correo Yahoo!: > http://correo.yahoo.com.mx/ > ___ > gtk-list mailing list > gtk-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-list > ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
problem with callback
Hello again I am making a window that has a menu, two drawing_area and a GtkEntry I added the following events (GDK_BUTTON1_MOTION_MASK, GDK_BUTTON2_MOTION_MASK, GDK_BUTTON_PRESS_MASK, GDK_VISIBILITY_NOTIFY_MASK) to the two drawing_area, and the respective callback, but the problem is that when I press a any key, the Gtkentry and the two drawing_are receive the signal, then call the function callback of the two drawing_area and writes the character in the Gtkentry. My question: how can I do for that when I press a key, The signal will be received only by selected widget, a drawing_area or the gtkEntry? ¡Capacidad ilimitada de almacenamiento en tu correo! No te preocupes más por el espacio de tu cuenta con Correo Yahoo!: http://correo.yahoo.com.mx/ ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
problem with callback
Hello again I am making a window that has a menu, two drawing_area and a GtkEntry I added the following events (GDK_BUTTON1_MOTION_MASK, GDK_BUTTON2_MOTION_MASK, GDK_BUTTON_PRESS_MASK, GDK_VISIBILITY_NOTIFY_MASK) to the two drawing_area, and the respective callback, but the problem is that when I press a any key, the Gtkentry and the two drawing_are receive the signal, then call the function callback of the two drawing_area and writes the character in the Gtkentry. My question: how can I do for that when I press a key, The signal will be received only by ddd selected? ¡Capacidad ilimitada de almacenamiento en tu correo! No te preocupes más por el espacio de tu cuenta con Correo Yahoo!: http://correo.yahoo.com.mx/ ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Problem with callback functions...
James Vanns wrote: > Okay. I have a function called create_toogle_window (). Within this function > I have a few GtkWidgets initiated as GtkToggleButtons (3 of) and then one OK > button. > > I have also a struct defined as within a header file: > > typedef struct _options { >gboolean bss; >gboolean caf; >gboolean sb; > } options; > > and an instance of it (automatic not pointer) within the named function > above. The automatic bit is probably your problem. By the time the OK button is pressed, the stack frame you allocated your struct on has long since gone. The usual technique is to have a struct for every window in your program. The struct keeps a pointer to each of your widgets, plus any other data you need to manage the display. Make a new struct with g_new() when you build a window, free the struct on a "destroy" signal, and pass a pointer to the struct with every signal connect for widgets in that window. An even better technique is to use gtk's class mechanism and do every window as a widget. There's an example in the tutorial. http://www.gtk.org/tutorial/sec-creatingacompositewidget.html HTH, John == Renaissance Autumn at the National Gallery A season of exhibitions, displays and events with a Renaissance theme. Pisanello: Painter to the Renaissance Court (24 October - 13 January 2002) For information and tickets: http://www.nationalgallery.org.uk/what/news/ren_autumn.htm ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
Problem with callback functions...
Hi everyone. Thanks in advance for at least reading my small problem! Okay. I have a function called create_toogle_window (). Within this function I have a few GtkWidgets initiated as GtkToggleButtons (3 of) and then one OK button. I have also a struct defined as within a header file: typedef struct _options { gboolean bss; gboolean caf; gboolean sb; } options; and an instance of it (automatic not pointer) within the named function above. Ok heres my problem. I am passing the options object defined (say it's called foo) to the three callbacks written for the 'toggled' event: gtk_signal_connect (GTK_OBJECT (checkbutton_caf), "toggled", GTK_SIGNAL_FUNC (on_checkbutton_caf_toggled), &foo); gtk_signal_connect (GTK_OBJECT (checkbutton_bss), "toggled", GTK_SIGNAL_FUNC (on_checkbutton_bss_toggled), &foo); gtk_signal_connect (GTK_OBJECT (checkbutton_sb), "toggled", GTK_SIGNAL_FUNC (on_checkbutton_sb_toggled), &foo); the GtkFuncs look like: void on_checkbutton_caf_toggled (GtkToggleButton * togglebutton, options *bar) { bar->caf = gtk_toggle_button_get_active (togglebutton); } The callbacks here are working fine. If I stick a g_print on the value of bar->element in the callbacks they all print 0 or 1 accordingly. Problem is though I want this struct (foo) passed to the button OK callback where I'll actually do something withit: gtk_signal_connect (GTK_OBJECT (button_transextract_ok), "clicked", GTK_SIGNAL_FUNC (on_button_transextract_ok_clicked), &foo); I.e. I select what I want using the togglebuttons, they store my config in the struct which is then passed to the button ok callback for manipulation/processing. All I get though when I do a g_print on the values of bar in the button ok callback function is rubbish, no nice 0's or 1's. WHat am I doing wrong and what do I need to do to fix it?? Should I be doing this another way?? Cheers for your time. Jim -- James Vanns BSc (Hons) MCP Software Engineer (UNIX / C) Galleon Ltd. ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list