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

GTK v1.2 Tutorial(英文)

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

  I hope this helps you on your way with creating notebooks for your GTK applications.

11. CList Widget

  The CList widget has replaced the List widget (which is still available).

  The CList widget is a multi-column list widget that is capable of handling literally thousands of rows of information. Each column can optionally have a title, which itself is optionally active, allowing us to bind a function to its selection.

11.1 Creating a CList widget

  Creating a CList is quite straightforward, once you have learned about widgets in general. It provides the almost standard two ways, that is the hard way, and the easy way. But before we create it, there is one thing we should figure out beforehand: how many columns should it have?

  Not all columns have to be visible and can be used to store data that is related to a certain cell in the list.


GtkWidget *gtk_clist_new ( gint columns );
GtkWidget *gtk_clist_new_with_titles( gint columns,
gchar *titles[] );

  The first form is very straightforward, the second might require some explanation. Each column can have a title associated with it, and this title can be a label or a button that reacts when we click on it. If we use the second form, we must provide pointers to the title texts, and the number of pointers should equal the number of columns specified. Of course we can always use the first form, and manually add titles later.

  Note: The CList widget does not have its own scrollbars and should be placed within a ScrolledWindow widget if your require this functionality. This is a change from the GTK 1.0 implementation.

11.2 Modes of operation

  There are several attributes that can be used to alter the behaviour of a CList. First there is


void gtk_clist_set_selection_mode( GtkCList *clist,
GtkSelectionModemode );

  which, as the name implies, sets the selection mode of the CList. The first argument is the CList widget, and the second specifies the cell selection mode (they are defined in gtkenums.h). At the time of this writing, the following modes are available to us:

  GTK_SELECTION_SINGLE - The selection is either NULL or contains a GList pointer for a single selected item.

  GTK_SELECTION_BROWSE - The selection is NULL if the list contains no widgets or insensitive ones only, otherwise it contains a GList pointer for one GList structure, and therefore exactly one list item.

  GTK_SELECTION_MULTIPLE - The selection is NULL if no list items are selected or a GList pointer for the first selected item. That in turn points to a GList structure for the second selected item and so on. This is currently the default for the CList widget.

  GTK_SELECTION_EXTENDED - The selection is always NULL.

  Others might be added in later revisions of GTK.

  We can also define what the border of the CList widget should look like. It is done through


void gtk_clist_set_shadow_type( GtkCList*clist,
GtkShadowTypeborder );

  The possible values for the second argument are

  GTK_SHADOW_NONE

  GTK_SHADOW_IN

  GTK_SHADOW_OUT

  GTK_SHADOW_ETCHED_IN

  GTK_SHADOW_ETCHED_OUT

11.3 Working with titles

  When you create a CList widget, you will also get a set of title buttons automatically. They live in the top of the CList window, and can act either as normal buttons that respond to being pressed, or they can be passive, in which case they are nothing more than a title. There are four different calls that aid us in setting the status of the title buttons.


void gtk_clist_column_title_active( GtkCList *clist,gint column );
void gtk_clist_column_title_passive( GtkCList *clist,gintcolumn );
void gtk_clist_column_titles_active( GtkCList *clist );
void gtk_clist_column_titles_passive( GtkCList *clist );

  An active title is one which acts as a normal button, a passive one is just a label. The first two calls above will activate/deactivate the title button above the specific column, while the last two calls activate/deactivate all title buttons in the supplied clist widget.

  But of course there are those cases when we don't want them at all, and so they can be hidden and shown at will using the following two calls.


void gtk_clist_column_titles_show( GtkCList *clist );
void gtk_clist_column_titles_hide( GtkCList *clist );


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



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

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号