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

GTK v1.2 Tutorial(英文)

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

  The xpm_label_box function could be used to pack xpm's and labels into any widget that can be a container.

  Notice in xpm_label_box how there is a call to gtk_widget_get_style. Every widget has a "style", consisting of foreground and background colors for a variety of situations, font selection, and other graphics data relevant to a widget. These style values are defaulted in each widget, and are required by many GDK function calls, such as gdk_pixmap_create_from_xpm, which here is given the "normal" background color. The style data of widgets may be customized, using GTK's rc files.

  Also notice the call to gtk_widget_realize after setting the window's border width. This function uses GDK to create the X windows related to the widget. The function is automatically called when you invoke gtk_widget_show for a widget, and so has not been shown in earlier examples. But the call to gdk_pixmap_create_from_xpm requires that its window argument refer to a real X window, so it is necessary to realize the widget before this GDK call.

  The Button widget has the following signals:

  pressed - emitted when pointer button is pressed within Button widget

  released - emitted when pointer button is released within Button widget

  clicked - emitted when pointer button is pressed and then released within Button widget

  enter - emitted when pointer enters Button widget

  leave - emitted when pointer leaves Button widget

6.2 Toggle Buttons

  Toggle buttons are derived from normal buttons and are very similar, except they will always be in one of two states, alternated by a click. They may be depressed, and when you click again, they will pop back up. Click again, and they will pop back down.

  Toggle buttons are the basis for check buttons and radio buttons, as such, many of the calls used for toggle buttons are inherited by radio and check buttons. I will point these out when we come to them.

  Creating a new toggle button:


GtkWidget *gtk_toggle_button_new( void );
GtkWidget *gtk_toggle_button_new_with_label( gchar *label );

  As you can imagine, these work identically to the normal button widget calls. The first creates a blank toggle button, and the second, a button with a label widget already packed into it.

  To retrieve the state of the toggle widget, including radio and check buttons, we use a construct as shown in our example below. This tests the state of the toggle, by accessing the active field of the toggle widget's structure, after first using the GTK_TOGGLE_BUTTON macro to cast the widget pointer into a toggle widget pointer. The signal of interest to us emitted by toggle buttons (the toggle button, check button, and radio button widgets) is the "toggled" signal. To check the state of these buttons, set up a signal handler to catch the toggled signal, and access the structure to determine its state. The callback will look something like:


void toggle_button_callback (GtkWidget *widget, gpointer data)
{
if (GTK_TOGGLE_BUTTON (widget)->active) 
{
/* If control reaches here, the toggle button is down */
} else {
/* If control reaches here, the toggle button is up */
}
}

  To force the state of a toggle button, and its children, the radio and check buttons, use this function:


void gtk_toggle_button_set_active( GtkToggleButton *toggle_button,
gint state );

  The above call can be used to set the state of the toggle button, and its children the radio and check buttons. Passing in your created button as the first argument, and a TRUE or FALSE for the second state argument to specify whether it should be down (depressed) or up (released). Default is up, or FALSE.

  Note that when you use the gtk_toggle_button_set_active() function, and the state is actually changed, it causes the "clicked" signal to be emitted from the button.


void gtk_toggle_button_toggled (GtkToggleButton *toggle_button);
This simply toggles the button, and emits the "toggled" signal. 

6.3 Check Buttons

  Check buttons inherit many properties and functions from the the toggle buttons above, but look a little different. Rather than being buttons with text inside them, they are small squares with the text to the right of them. These are often used for toggling options on and off in applications.

  The two creation functions are similar to those of the normal button.

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

上一页 1 2 3 4 5 6 7 8 9 10 11 1213 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号