当前位置: 技术问答>linux和unix
GTK想请问一个关于右键的问题
来源: 互联网 发布时间:2016-06-10
本文导语: 我已经可以出现右键菜单 也可以传送event给我所写的function 而当我右键点选时 出现了菜单 却无法同时选中档案 想请问有什么方式做呢 以下是我右键菜单的code //////點選右鍵後的動作///////////////////////////////////////////...
我已经可以出现右键菜单
也可以传送event给我所写的function
而当我右键点选时 出现了菜单
却无法同时选中档案
想请问有什么方式做呢
以下是我右键菜单的code
//////點選右鍵後的動作//////////////////////////////////////////////////////////////////////
static void do_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
{
GtkWidget *menu;
GtkWidget *open, *new, *cut, *copy, *paste, *rename, *delete;
GtkWidget *a;
int button, event_time;
menu = gtk_menu_new ();
// ... add menu items ...
if (event)
{
button = event->button;
event_time = event->time;
}
else
{
button = 0;
event_time = gtk_get_current_event_time ();
}
new = gtk_menu_item_new_with_label("New Folder");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), new);
g_signal_connect(G_OBJECT(new), "activate",
G_CALLBACK(new_folder), main_store);
open = gtk_menu_item_new_with_label("Open File");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), open);
g_signal_connect(G_OBJECT(open), "activate",
G_CALLBACK(open_file), NULL);
a = gtk_menu_item_new_with_label("--------------------");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), a);
cut = gtk_menu_item_new_with_label("Cut");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), cut);
g_signal_connect(G_OBJECT(cut), "activate",
G_CALLBACK(cut_item), NULL);
copy = gtk_menu_item_new_with_label("Copy");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), copy);
g_signal_connect(G_OBJECT(copy), "activate",
G_CALLBACK(copy_item), NULL);
paste = gtk_menu_item_new_with_label("paste");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), paste);
g_signal_connect(G_OBJECT(paste), "activate",
G_CALLBACK(paste_item), main_store);
rename = gtk_menu_item_new_with_label("Rename");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), rename);
g_signal_connect(G_OBJECT(rename), "activate",
G_CALLBACK(rename_item), main_store);
delete = gtk_menu_item_new_with_label("Delete");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), delete);
g_signal_connect(G_OBJECT(delete), "activate",
G_CALLBACK(remove_item), main_store);
gtk_menu_attach_to_widget (GTK_MENU (menu), my_widget, NULL);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
button, event_time);
gtk_widget_show_all(GTK_WIDGET(menu));
return;
}
//////判別是否點選右鍵////////////////////////////////////////////////////////////////////////////
static gboolean my_widget_button_press_event_handler (GtkWidget *widget,
GdkEventButton *event, gpointer data)
{
// Ignore double-clicks and triple-clicks
if (event->button == 3 && event->type == GDK_BUTTON_PRESS
)
{
do_popup_menu (widget, event);
return TRUE;
}
else if(event->button == 1)
{
// item_activated (icon_view, tree_path, user_data);
}
return FALSE;
}
/////popup handler////////////////////////////////////////////////////////////////////////////
static gboolean my_widget_popup_menu_handler (GtkWidget *widget)
{
do_popup_menu (widget, NULL);
return TRUE;
}
也可以传送event给我所写的function
而当我右键点选时 出现了菜单
却无法同时选中档案
想请问有什么方式做呢
以下是我右键菜单的code
//////點選右鍵後的動作//////////////////////////////////////////////////////////////////////
static void do_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
{
GtkWidget *menu;
GtkWidget *open, *new, *cut, *copy, *paste, *rename, *delete;
GtkWidget *a;
int button, event_time;
menu = gtk_menu_new ();
// ... add menu items ...
if (event)
{
button = event->button;
event_time = event->time;
}
else
{
button = 0;
event_time = gtk_get_current_event_time ();
}
new = gtk_menu_item_new_with_label("New Folder");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), new);
g_signal_connect(G_OBJECT(new), "activate",
G_CALLBACK(new_folder), main_store);
open = gtk_menu_item_new_with_label("Open File");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), open);
g_signal_connect(G_OBJECT(open), "activate",
G_CALLBACK(open_file), NULL);
a = gtk_menu_item_new_with_label("--------------------");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), a);
cut = gtk_menu_item_new_with_label("Cut");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), cut);
g_signal_connect(G_OBJECT(cut), "activate",
G_CALLBACK(cut_item), NULL);
copy = gtk_menu_item_new_with_label("Copy");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), copy);
g_signal_connect(G_OBJECT(copy), "activate",
G_CALLBACK(copy_item), NULL);
paste = gtk_menu_item_new_with_label("paste");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), paste);
g_signal_connect(G_OBJECT(paste), "activate",
G_CALLBACK(paste_item), main_store);
rename = gtk_menu_item_new_with_label("Rename");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), rename);
g_signal_connect(G_OBJECT(rename), "activate",
G_CALLBACK(rename_item), main_store);
delete = gtk_menu_item_new_with_label("Delete");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), delete);
g_signal_connect(G_OBJECT(delete), "activate",
G_CALLBACK(remove_item), main_store);
gtk_menu_attach_to_widget (GTK_MENU (menu), my_widget, NULL);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
button, event_time);
gtk_widget_show_all(GTK_WIDGET(menu));
return;
}
//////判別是否點選右鍵////////////////////////////////////////////////////////////////////////////
static gboolean my_widget_button_press_event_handler (GtkWidget *widget,
GdkEventButton *event, gpointer data)
{
// Ignore double-clicks and triple-clicks
if (event->button == 3 && event->type == GDK_BUTTON_PRESS
)
{
do_popup_menu (widget, event);
return TRUE;
}
else if(event->button == 1)
{
// item_activated (icon_view, tree_path, user_data);
}
return FALSE;
}
/////popup handler////////////////////////////////////////////////////////////////////////////
static gboolean my_widget_popup_menu_handler (GtkWidget *widget)
{
do_popup_menu (widget, NULL);
return TRUE;
}
|