Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->系统管理 ->正文

GTK v1.2 Tutorial(英文)

来源:Linux-cn.com 作者:Webmaster 时间:2007-05-05 点击: [收藏] [投稿]

2.2 Compiling Hello World

  To compile use:


gcc -Wall -g helloworld.c -o helloworld `gtk-config --cflags` 
`gtk-config --libs`

  This uses the program gtk-config, which comes with GTK. This program "knows" what compiler switches are needed to compile programs that use GTK. gtk-config --cflags will output a list of include directories for the compiler to look in, and gtk-config --libs will output the list of libraries for the compiler to link with and the directories to find them in. In the above example they could have been combined into a single instance, such as `gtk-config --cflags --libs`.

  Note that the type of single quote used in the compile command above is significant.

  The libraries that are usually linked in are:

  The GTK library (-lgtk), the widget library, based on top of GDK.

  The GDK library (-lgdk), the Xlib wrapper.

  The gmodule library (-lgmodule), which is used to load run time extensions.

  The GLib library (-lglib), containing miscellaneous functions; only g_print() is used in this particular example. GTK is built on top of glib so you will always require this library. See the section on GLib for details.

  The Xlib library (-lX11) which is used by GDK.

  The Xext library (-lXext). This contains code for shared memory pixmaps and other X extensions.

  The math library (-lm). This is used by GTK for various purposes.

2.3 Theory of Signals and Callbacks

  Before we look in detail at helloworld, we'll discuss signals and callbacks. GTK is an event driven toolkit, which means it will sleep in gtk_main until an event occurs and control is passed to the appropriate function.

  This passing of control is done using the idea of "signals". (Note that these signals are not the same as the Unix system signals, and are not implemented using them, although the terminology is almost identical.) When an event occurs, such as the press of a mouse button, the appropriate signal will be "emitted" by the widget that was pressed. This is how GTK does most of its useful work. There are signals that all widgets inherit, such as "destroy", and there are signals that are widget specific, such as "toggled" on a toggle button.

  To make a button perform an action, we set up a signal handler to catch these signals and call the appropriate function. This is done by using a function such as:


gint gtk_signal_connect( GtkObject *object,
 gchar *name,
 GtkSignalFuncfunc,
 gpointer func_data );

  where the first argument is the widget which will be emitting the signal, and the second the name of the signal you wish to catch. The third is the function you wish to be called when it is caught, and the fourth, the data you wish to have passed to this function.

  The function specified in the third argument is called a "callback function", and should generally be of the form


void callback_func( GtkWidget *widget,
gpointer callback_data );

  where the first argument will be a pointer to the widget that emitted the signal, and the second a pointer to the data given as the last argument to the gtk_signal_connect() function as shown above.

  Note that the above form for a signal callback function declaration is only a general guide, as some widget specific signals generate different calling parameters. For example, the CList "select_row" signal provides both row and column parameters.

  Another call used in the helloworld example, is:


gint gtk_signal_connect_object( GtkObject *object,
gchar *name,
GtkSignalFuncfunc,
GtkObject *slot_object );

  gtk_signal_connect_object() is the same as gtk_signal_connect() except that the callback function only uses one argument, a pointer to a GTK object. So when using this function to connect signals, the callback should be of the form


void callback_func( GtkObject *object );

  where the object is usually a widget. We usually don't setup callbacks for gtk_signal_connect_object however. They are usually used to call a GTK function that accepts a single widget or object as an argument, as is the case in our helloworld example.

  The purpose of having two functions to connect signals is simply to allow the callbacks to have a different number of arguments. Many functions in the GTK library accept only a single GtkWidget pointer as an argument, so you want to use the gtk_signal_connect_object() for these, whereas for your functions, you may need to have additional data supplied to the callbacks.

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<

上一页 1 2 34 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 下一页


上一篇:GTK入门导引   下一篇:GDK Reference Manual

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
·Motorola微处理器bootloader分析与应用
·Fedora Core5 NFS服务器搭建过程介绍
·Linux系统:让内存不再泄漏的实用技巧
·新手看招 手把手教你安装VMware虚拟机
·“侵权事件” 红帽称微软企图干扰用户
·删除Linux后 如何找回Windows启动菜单
·菜鸟乐园 Linux中常见文件系统格式介绍
·Linux操作系统下IPTables配置方法详解
·实用技巧 Linux系统的经典使用技巧八则
·Linux系统文件优化及磁盘检查方法介绍
推荐文章
·Linux技巧:bz2文件如何解压缩
·用MRTG检测Linux网络性能
·红帽宣布开放JBoss中核心系统管理软
·如何设定与维持准确的电脑时钟
·Linux系统中找出并解决程序错误方法
·在Linux下成功运行最新的QQ和MSN
·如何重新规划分割区
·Webmin---Linux下的用户管理工具
精彩文章
·起步走 二十五步跟我搞定Linux系统
·几个JSP应用模板
·浅析:从xml生成Java类
·Linux下ip隧道研究(1)
·CORBA及MICO简介
·用Linux防火墙构建DMZ
·linux汉化大全(六)
·用Java Mail API查看邮件
·在Linux Shell程序中进行身份验证
·Linux指令大全(2)
·rootkit综述
·在linux7.1上安装jdk+tomcat+orac
·Linux御敌策略谈
·巧用KDE
·Linux 网管 123 --- 第8章. 备份及
·Socket建立连接的过程
·Linux命令Man解释:ftpaccess(5) :ft
·和luster一起学习系统调用(3)
·文件系统安全--EXT2文件系统的属性
·打造完美Linux系统:疑难杂症的解决
·Bean管理持续化实例
·Linux 每次启动时钟日期就多了 8 小
·基于Linux的Web服务器性能测试
·JDK开发工具包(三)
·Linux平台C++类库tinycxx使用说明
·和luster一起学习java编程(4)
Power by linux-cn.com 粤ICP备05006655号