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

GTK v1.2 Tutorial(英文)

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

9.14 File Selections

  The file selection widget is a quick and simple way to display a File dialog box. It comes complete with Ok, Cancel, and Help buttons, a great way to cut down on programming time.

  To create a new file selection box use:


GtkWidget *gtk_file_selection_new( gchar *title );

  To set the filename, for example to bring up a specific directory, or give a default filename, use this function:


void gtk_file_selection_set_filename( GtkFileSelection *filesel,
gchar*filename );

  To grab the text that the user has entered or clicked on, use this function:


gchar *gtk_file_selection_get_filename( GtkFileSelection *filesel );

  There are also pointers to the widgets contained within the file selection widget. These are:

  dir_list

  file_list

  selection_entry

  selection_text

  main_vbox

  ok_button

  cancel_button

  help_button

  Most likely you will want to use the ok_button, cancel_button, and help_button pointers in signaling their use.

  Included here is an example stolen from testgtk.c, modified to run on its own. As you will see, there is nothing much to creating a file selection widget. While in this example the Help button appears on the screen, it does nothing as there is not a signal attached to it.


/* example-start filesel filesel.c */
#include <gtk/gtk.h>
/* Get the selected filename and print it to the console */
void file_ok_sel( GtkWidget*w,GtkFileSelection *fs )
{
g_print ("%s
", gtk_file_selection_get_filename 
(GTK_FILE_SELECTION (fs)));
}
void destroy( GtkWidget *widget,
gpointer data )
{
gtk_main_quit ();
}
int main( int argc,
char *argv[] )
{
GtkWidget *filew;
gtk_init (&argc, &argv);
/* Create a new file selection widget */
filew = gtk_file_selection_new ("File selection");
gtk_signal_connect (GTK_OBJECT (filew), "destroy",
(GtkSignalFunc) destroy, &filew);
/* Connect the ok_button to file_ok_sel function */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked", (GtkSignalFunc) file_ok_sel, filew );
/* Connect the cancel_button to destroy the widget */
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
(filew)->cancel_button),
 "clicked", (GtkSignalFunc) gtk_widget_destroy,
 GTK_OBJECT (filew));
/* Lets set the filename, as if this were a save dialog, and we are giving
 a default filename */
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), 
 "penguin.png");
gtk_widget_show(filew);
gtk_main ();
return 0;
}
/* example-end */

10. Container Widgets

10.1 The EventBox

  Some GTK widgets don't have associated X windows, so they just draw on their parents. Because of this, they cannot receive events and if they are incorrectly sized, they don't clip so you can get messy overwriting, etc. If you require more from these widgets, the EventBox is for you.

  At first glance, the EventBox widget might appear to be totally useless. It draws nothing on the screen and responds to no events. However, it does serve a function - it provides an X window for its child widget. This is important as many GTK widgets do not have an associated X window. Not having an X window saves memory and improves performance, but also has some drawbacks. A widget without an X window cannot receive events, and does not perform any clipping on its contents. Although the name EventBox emphasizes the event-handling function, the widget can also be used for clipping. (and more, see the example below).

  To create a new EventBox widget, use:


GtkWidget *gtk_event_box_new( void );

  A child widget can then be added to this EventBox:


gtk_container_add( GTK_CONTAINER(event_box), child_widget );

  The following example demonstrates both uses of an EventBox - a label is created that is clipped to a small box, and set up so that a mouse-click on the label causes the program to exit. Resizing the window reveals varying amounts of the label.



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

上一页 1 2 3 4 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 3637 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系统文件优化及磁盘检查方法介绍
Power by linux-cn.com 粤ICP备05006655号