当前位置: 技术问答>linux和unix
求教gtk_widget_can_activate_accel()函数的作用。
来源: 互联网 发布时间:2016-05-24
本文导语: 关于该函数的作用,在GTK+手册中描述如下: Determines whether an accelerator that activates the signal identified by signal_id can currently be activated. This is done by emitting the "can-activate-accel" signal on widget; if the signal isn'...
关于该函数的作用,在GTK+手册中描述如下:
Determines whether an accelerator that activates the signal identified by signal_id can currently be activated. This is done by emitting the "can-activate-accel" signal on widget; if the signal isn't overridden by a handler or in a derived widget, then the default check is that the widget must be sensitive, and the widget and all its ancestors mapped.
我的理解是,如果在程序中为某个构件设置了一个快捷键。将构件和信号标识符作为参数传递给gtk_widget_can_activate_accel()函数,那么使用快捷键时can-activate-accel信号被抛出。(这一点我在程序中已证实)
那么关于activate-accel信号的描述如下:
Determines whether an accelerator that activates the signal identified by signal_id can currently be activated. This signal is present to allow applications and derived widgets to override the default GtkWidget handling for determining whether an accelerator can be activated.
而我下载的一本《Foundations of GTK+ Development》(Apress)上的描述为:
You can use this signal to override the default handler for whether an accelerator can be activated. You should return TRUE if the signal can be activated.
我认为,activate-accel信号的回调函数如果返回TRUE,快捷键才会执行。但是我实际的程序中,为什么怎么搞都没有用?
代码如下:
Determines whether an accelerator that activates the signal identified by signal_id can currently be activated. This is done by emitting the "can-activate-accel" signal on widget; if the signal isn't overridden by a handler or in a derived widget, then the default check is that the widget must be sensitive, and the widget and all its ancestors mapped.
我的理解是,如果在程序中为某个构件设置了一个快捷键。将构件和信号标识符作为参数传递给gtk_widget_can_activate_accel()函数,那么使用快捷键时can-activate-accel信号被抛出。(这一点我在程序中已证实)
那么关于activate-accel信号的描述如下:
Determines whether an accelerator that activates the signal identified by signal_id can currently be activated. This signal is present to allow applications and derived widgets to override the default GtkWidget handling for determining whether an accelerator can be activated.
而我下载的一本《Foundations of GTK+ Development》(Apress)上的描述为:
You can use this signal to override the default handler for whether an accelerator can be activated. You should return TRUE if the signal can be activated.
我认为,activate-accel信号的回调函数如果返回TRUE,快捷键才会执行。但是我实际的程序中,为什么怎么搞都没有用?
代码如下:
gboolean activate_accel(GtkWidget *button, gint signal_id)
{
printf("%dn", signal_id); // 这条能把信号标识符输出
return FALSE; // 我想让快捷键失效
}
………………// 省略其它回调函数
main(){
………………
button = gtk_button_new_with_label("计数 CTRL + A");
gtk_widget_add_accelerator (button, "clicked", accel_group,
GDK_A, (GdkModifierType) GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE); // 注册了一个快捷键
………………
signal_id = g_signal_connect((gpointer) button, "clicked", G_CALLBACK(label_const),
(gpointer) label);
gtk_widget_can_activate_accel(button, signal_id); // 注意!!!这里是关键!!!
g_signal_connect((gpointer) button, "can-activate-accel",
G_CALLBACK(activate_accel), NULL); // 这个地方处理can-activate-accel函数!!!
………………
}
|
帮顶吧。没玩过GTK。