possible bug?



I've encountered an inconsistency in GTK+ that may be a bug.
I want to verify I'm not doing anything wrong, before I submit a bug report.

I want to attach a popup menu (via the button-press-event) to a few controls.
When I use the same code on a GtkEntry and a GtkButton, I must click on menu
items *twice* before anything happens on the GtkEntry.  With the GtkButton,
it works as expected (one click).

I've attached a sample program, exhibiting the behavior.

-- 
Evan Martin - eeyem@u.washington.edu - http://students.washington.edu/eeyem

#include <gtk/gtk.h>

gint menu_cb(GtkWidget *widget, GdkEvent *event, gpointer data) {
	if (event->type == GDK_BUTTON_PRESS) {
		GdkEventButton *eventbutton = (GdkEventButton*) event;
		if (eventbutton->button == 3) {
			GtkWidget *menu;
			GtkWidget *item;
			menu = gtk_menu_new();
			item = gtk_menu_item_new_with_label("Quit");
			gtk_signal_connect(GTK_OBJECT(item), "activate",
				GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
			gtk_widget_show(item);
			gtk_menu_append(GTK_MENU(menu), item);
			gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
				eventbutton->button, eventbutton->time);
			return TRUE;
		}
	}
	return FALSE;
}

int main(int argc, char* argv[]) {
	GtkWidget *win, *entry, *hbox, *button;

	gtk_init(&argc, &argv);

	win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_signal_connect(GTK_OBJECT(win), "delete_event",
			GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

	hbox = gtk_hbox_new(FALSE, 5);
	gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);

	entry = gtk_entry_new();
	gtk_signal_connect(GTK_OBJECT(entry), "button-press-event",
		GTK_SIGNAL_FUNC(menu_cb), NULL);
	gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);

	button = gtk_button_new_with_label("Sample");
	gtk_signal_connect(GTK_OBJECT(button), "button-press-event",
		GTK_SIGNAL_FUNC(menu_cb), NULL);
	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);

	gtk_container_add(GTK_CONTAINER(win), hbox);

	gtk_widget_show_all(win);

	gtk_main();

	return 0;
}


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