Hello,
I'm having difficulties understanding why I can't create bindings for catching right mouse button clicks on some widgets, e.g. GtkOptionMenu and GtkFileSelectorButton. In the attached program I create two widgets, a button, and a file selector button. The button is attached to a clicked signal as well as to a gtk-button-press-event signal. In the gtk-button-press event handler I can choose the behaviour based on what button is pressed. But the same binding doesn't work for the GtkFileSelectorButton. My binding to "button-press-event" is blocked. Since the GtkFileSelectorButton responds to right click, then obviously it is setup to receive button-press events. But why doesn't it receive my handler? What am I missing?
(In my real application, a RAD environment, I would like to popup a menu for (almost) all widgets when the right mouse button is clicked. But the behaviour that the button-press-event is blocked stops me from doing that.)
Attached my sample program.
Thanks!
Dov
//======================================================================
// why-no-event.c - Why is there no event from the option button.
//
// Dov Grobgeld <dov.grobgeld@xxxxxxxxx>
// Thu May 21 19:24:40 2009
//----------------------------------------------------------------------
#include <gtk/gtk.h>
#include <stdlib.h>
gboolean cb_button_press_event(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data);
gboolean cb_clicked(GtkWidget *widget,
gpointer user_data);
int main(int argc, char **argv)
{
GtkWidget *w_win, *w_box, *w_button, *w_fs_button;
gtk_init(&argc, &argv);
w_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
w_box = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(w_win), w_box);
w_button = gtk_button_new_with_label("Press");
gtk_box_pack_start(GTK_BOX(w_box), w_button, FALSE, FALSE, 0);
w_fs_button = gtk_file_chooser_button_new("Select",
GTK_FILE_CHOOSER_ACTION_OPEN);
gtk_box_pack_start(GTK_BOX(w_box), w_fs_button, FALSE, FALSE, 0);
gtk_widget_show_all(w_win);
// Now connect the press button to both a clicked and a button-press-event
g_signal_connect(w_button, "clicked", G_CALLBACK(cb_clicked), NULL);
g_signal_connect(w_button, "button-press-event",
G_CALLBACK(cb_button_press_event), NULL);
// Connect the file selector to catch a button-press-event on
// the file selector button, but the binding doesn't work!
g_signal_connect(w_fs_button, "button-press-event",
G_CALLBACK(cb_button_press_event), NULL);
gtk_main();
exit(0);
}
gboolean cb_button_press_event(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
printf("cb_button_press_event\n");
if (event->button == 3) {
printf("Got right mouse button!\n");
return TRUE;
}
return FALSE;
}
gboolean cb_clicked(GtkWidget *widget,
gpointer user_data)
{
printf("cb_clicked\n");
return TRUE;
}
I'm having difficulties understanding why I can't create bindings for catching right mouse button clicks on some widgets, e.g. GtkOptionMenu and GtkFileSelectorButton. In the attached program I create two widgets, a button, and a file selector button. The button is attached to a clicked signal as well as to a gtk-button-press-event signal. In the gtk-button-press event handler I can choose the behaviour based on what button is pressed. But the same binding doesn't work for the GtkFileSelectorButton. My binding to "button-press-event" is blocked. Since the GtkFileSelectorButton responds to right click, then obviously it is setup to receive button-press events. But why doesn't it receive my handler? What am I missing?
(In my real application, a RAD environment, I would like to popup a menu for (almost) all widgets when the right mouse button is clicked. But the behaviour that the button-press-event is blocked stops me from doing that.)
Attached my sample program.
Thanks!
Dov
//======================================================================
// why-no-event.c - Why is there no event from the option button.
//
// Dov Grobgeld <dov.grobgeld@xxxxxxxxx>
// Thu May 21 19:24:40 2009
//----------------------------------------------------------------------
#include <gtk/gtk.h>
#include <stdlib.h>
gboolean cb_button_press_event(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data);
gboolean cb_clicked(GtkWidget *widget,
gpointer user_data);
int main(int argc, char **argv)
{
GtkWidget *w_win, *w_box, *w_button, *w_fs_button;
gtk_init(&argc, &argv);
w_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
w_box = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(w_win), w_box);
w_button = gtk_button_new_with_label("Press");
gtk_box_pack_start(GTK_BOX(w_box), w_button, FALSE, FALSE, 0);
w_fs_button = gtk_file_chooser_button_new("Select",
GTK_FILE_CHOOSER_ACTION_OPEN);
gtk_box_pack_start(GTK_BOX(w_box), w_fs_button, FALSE, FALSE, 0);
gtk_widget_show_all(w_win);
// Now connect the press button to both a clicked and a button-press-event
g_signal_connect(w_button, "clicked", G_CALLBACK(cb_clicked), NULL);
g_signal_connect(w_button, "button-press-event",
G_CALLBACK(cb_button_press_event), NULL);
// Connect the file selector to catch a button-press-event on
// the file selector button, but the binding doesn't work!
g_signal_connect(w_fs_button, "button-press-event",
G_CALLBACK(cb_button_press_event), NULL);
gtk_main();
exit(0);
}
gboolean cb_button_press_event(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
printf("cb_button_press_event\n");
if (event->button == 3) {
printf("Got right mouse button!\n");
return TRUE;
}
return FALSE;
}
gboolean cb_clicked(GtkWidget *widget,
gpointer user_data)
{
printf("cb_clicked\n");
return TRUE;
}
_______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list