求教gtk_widget_can_activate_accel()函数的作用。

时哲 2009-03-21 02:31:34
关于该函数的作用,在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,快捷键才会执行。但是我实际的程序中,为什么怎么搞都没有用?





代码如下:

gboolean activate_accel(GtkWidget *button, gint signal_id)
{
printf("%d\n", 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函数!!!

………………
}
...全文
74 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
帮顶吧。没玩过GTK。

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧