right click to popup menu in vte_termianl



hi all, 
I read this FAQ(http://www.mhatt.aps.anl.gov/dohn/programming/gtk-2.0/gtk-faq/x670.html)
,
and try to popup menu when right click on a vte_termial, but failed.

but I successed in a normal label, why fialed on a vte_terminal?
Here is my test code attached.
                            csj
#include <gtk/gtk.h>
#include <vte/vte.h>

void copy_text(GtkWidget *menuitem) {
	g_print("copy test\n");
}

void paste_text(GtkWidget *menuitem) {
	g_print("paste test\n");
}

gint button_press_event (GtkWidget *widget, GdkEventButton *event )
{
	if (event -> button ==3)
	{
		GtkWidget *menu, *copy_item, *paste_item;
		GdkEventButton *bevent = (GdkEventButton *) event;
		menu = gtk_menu_new ();
		copy_item = gtk_menu_item_new_with_label("copy");
		g_signal_connect(copy_item,"activate",G_CALLBACK(copy_text),NULL);
		paste_item = gtk_menu_item_new_with_label("paste");
		g_signal_connect(paste_item,"activate",G_CALLBACK(paste_text),NULL);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), copy_item);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), paste_item);
		gtk_widget_show_all(menu);
		gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL,bevent->button, bevent->time);
		return TRUE;
     }
     return FALSE;

}


int main(int argc, char* argv[])
{
	GtkWidget *window, *event_box, *terminal;
	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(window,"destroy",gtk_main_quit,NULL);

	event_box = gtk_event_box_new ();
	gtk_container_add(GTK_CONTAINER(window),event_box);
	
	terminal = vte_terminal_new();
	vte_terminal_set_size(VTE_TERMINAL(terminal),80,24);
	gtk_container_add (GTK_CONTAINER (event_box), terminal);
	
	gtk_widget_set_events (event_box, GDK_BUTTON_PRESS_MASK);
	g_signal_connect (G_OBJECT (event_box), "button_press_event",G_CALLBACK (button_press_event), NULL);
	
	gtk_widget_show_all(window);
	gtk_main();
	return 0;
}


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