我根据所选gtkTreeView行中的单词创建了运行时创建的菜单。
gboolean
menu_RELEASE(GtkObject *object, GdkEvent *event, gpointer user_data)
{
if (strlen(user_data) > 0)
{
gtk_entry_set_text(GTK_ENTRY(entry1), user_data);
gtk_widget_grab_focus(entry1);
}
else
main_art(get_sifra());
return TRUE;
}
gboolean
treeview1_BUTTONRELEASE(GtkWidget *widget, GdkEventButton *event, gpointer *user_data)
{
if (event->type == GDK_BUTTON_RELEASE && event->button == 3)
{
char *ntext;
treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
if (gtk_tree_selection_get_selected(treesel, &model ,&iter))
{
gtk_tree_model_get(model, &iter, cNaziv, &ntext, -1);
GtkWidget *menu, *menu_item;
menu = gtk_menu_new();
char *sresult = NULL;
sresult = strtok(ntext, " ");
while(sresult != NULL)
{
if (strlen(sresult)>1)
{
menu_item = gtk_menu_item_new_with_label(sresult);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
g_signal_connect(G_OBJECT(menu_item), "button-release-event", G_CALLBACK(menu_RELEASE), (gpointer)sresult);
}
sresult = strtok(NULL, " ");
}
menu_item = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
//
menu_item = gtk_image_menu_item_new_with_label("Uredi...");
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), GTK_WIDGET(gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU)));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
g_signal_connect(G_OBJECT(menu_item), "button-release-event", G_CALLBACK(menu_RELEASE), (gpointer)"");
//
gtk_widget_show_all(menu);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
return TRUE;
}
}
return FALSE;
}
当菜单项被释放时,来自" menu_RELEASE"应该出现。 但是发生了什么? 菜单不会消失,保持可见和活跃状态。
我的代码出了什么问题?