概述
信号函数:
gint gtk_signal_connect(GtkObject *object,gchar *name,GtkSignalFuncfunc,gpointer func_data);
回掉函数的格式:
void callback_func(GtkEidget *widget,gpointer callback_data);
GTK的事件:gtk组件的行为或者X服务器发送的事件可以与下列事件联系起来:
button_press_event <wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong> 按钮按下</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong><br> button_release_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>按钮释放<br> motion_notify_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>鼠标移动<br> delete_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>使用窗口管理器关闭<br> destroy_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>关闭<br> expose_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>曝光<br> key_press_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>按键按下<br> key_release_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>按键释放<br> enter_notify_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>鼠标指针进入组件<br> leave_notify_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>鼠标指针离开组件<br> configure_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>属性改变<br> focus_in_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>获得聚焦<br> focus_out_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>失去聚焦<br> map_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>映射<br> unmap_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>消失<br> property_notify_even</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>属性改变<br> selection_clear_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>选择清除<br> selection_request_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>选择请求<br> selection_notify_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>选择通知<br> proximity_in_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>接近<br> proximity_out_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>离开<br> drag_begin_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>拖开始<br> drag_request_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>拖请求<br> drag_end_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>拖结束<br> drop_enter_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>放进入<br> drop_leave_event</strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong></strong></span><wbr><span style="font-size:18px"><strong>放离开<br> drop_data_available_event</strong></span><wbr><span style="font-size:18px"><strong> 放数据可用</strong></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
除有前面描述的信号机制外,还有一套 events 反映 X事件机制。回调函数可以与这些事件连接。这些事件是:
- event
- button_press_event
- button_release_event
- scroll_event
- motion_notify_event
- delete_event
- destroy_event
- expose_event
- key_press_event
- key_release_event
- enter_notify_event
- leave_notify_event
- configure_event
- focus_in_event
- focus_out_event
- map_event
- unmap_event
- property_notify_event
- selection_clear_event
- selection_request_event
- selection_notify_event
- proximity_in_event
- proximity_out_event
- visibility_notify_event
- client_event
- no_expose_event
- window_state_event
为了连接一个回调函数到这些事件之一,你使用函数 g_signal_connect(),像前面介绍的一样,用上面事件名之一作为name 参数。事件的回调函数与信号的回调函数有一点点不同:
gint callback_func( GtkWidget *widget,GdkEvent *event,gpointer callback_data );
GdkEvent 是一个 C 联合结构,它的类型依赖于上述事件中的哪个事件发生了。为了让我们得知发生了哪个事件,每个可能的类型都有一个 type 成员来反映发生的事件。事件结构的其它部分将依赖于这个事件的类型。类型的可能的值有:
GDK_NOTHING
GDK_DELETE
GDK_DESTROY
GDK_EXPOSE
GDK_MOTION_NOTIFY
GDK_BUTTON_PRESS
GDK_2BUTTON_PRESS
GDK_3BUTTON_PRESS
GDK_BUTTON_RELEASE
GDK_KEY_PRESS
GDK_KEY_RELEASE
GDK_ENTER_NOTIFY
GDK_LEAVE_NOTIFY
GDK_FOCUS_CHANGE
GDK_CONFIGURE
GDK_MAP
GDK_UNMAP
GDK_PROPERTY_NOTIFY
GDK_SELECTION_CLEAR
GDK_SELECTION_REQUEST
GDK_SELECTION_NOTIFY
GDK_PROXIMITY_IN
GDK_PROXIMITY_OUT
GDK_DRAG_ENTER
GDK_DRAG_LEAVE
GDK_DRAG_MOTION
GDK_DRAG_STATUS
GDK_DROP_START
GDK_DROP_FINISHED
GDK_CLIENT_EVENT
GDK_VISIBILITY_NOTIFY
GDK_NO_EXPOSE
GDK_SCROLL
GDK_WINDOW_STATE
GDK_SETTING
|
所以,连接一个回调函数到这些事件之一,我们会这样用:
g_signal_connect (G_OBJECT (button), "button_press_event",
G_CALLBACK (button_press_callback), NULL);
|
这里假定 button 是一个按钮构件。现在,当鼠标位于按钮上并按一下鼠标时,函数 button_press_callback() 会被调用。这个函数应该声明为:
static gint button_press_callback( GtkWidget *widget,
GdkEventButton *event,
gpointer data );
|
注意,我们可以把第二个参数类型声明为 GdkEventButton,因为我们知道哪个类型的事件会发生。
这个函数的返回值指示这个事件是否应该由 GTK 事件处理机制做进一步的传播。返回 TRUE 指示这个事件已经处理了,且不应该做进一步传播。返回 FALSE 继续正常的事件处理。详见高级事件和信号处理这一章。
GdkEvent 数据类型详情请参见附录 GDK 事件类型。
GDK 选中区和拖放的接口函数也发出许多事件,在 GTK 中用信号来反映。下列信号的内容详见源构件上的信号和目的构件上的信号这两章:
- selection_received
- selection_get
- drag_begin_event
- drag_end_event
- drag_data_delete
- drag_motion
- drag_drop
- drag_data_get
- drag_data_received
最后
以上就是受伤老虎为你收集整理的【GTK】信号量(signal)大全的全部内容,希望文章能够帮你解决【GTK】信号量(signal)大全所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复