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

GTK v1.2 Tutorial(英文)

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

10.11 Toolbar

  Toolbars are usually used to group some number of widgets in order to simplify customization of their look and layout. Typically a toolbar consists of buttons with icons, labels and tooltips, but any other widget can also be put inside a toolbar. Finally, items can be arranged horizontally or vertically and buttons can be displayed with icons, labels, or both.

  Creating a toolbar is (as one may already suspect) done with the following function:


GtkWidget *gtk_toolbar_new( GtkOrientation orientation,
GtkToolbarStylestyle );

  where orientation may be one of:

  GTK_ORIENTATION_HORIZONTAL

  GTK_ORIENTATION_VERTICAL

  and style one of:

  GTK_TOOLBAR_TEXT

  GTK_TOOLBAR_ICONS

  GTK_TOOLBAR_BOTH

  The style applies to all the buttons created with the `item' functions (not to buttons inserted into toolbar as separate widgets).

  After creating a toolbar one can append, prepend and insert items (that means simple text strings) or elements (that means any widget types) into the toolbar. To describe an item we need a label text, a tooltip text, a private tooltip text, an icon for the button and a callback function for it. For example, to append or prepend an item you may use the following functions:


GtkWidget *gtk_toolbar_append_item( GtkToolbar*toolbar,
const char*text,const char*tooltip_text,const char*tooltip_private_text,
GtkWidget *icon,GtkSignalFunccallback,gpointer user_data );
GtkWidget *gtk_toolbar_prepend_item( GtkToolbar*toolbar,
const char*text,const char*tooltip_text,const char*tooltip_private_text,
GtkWidget *icon,GtkSignalFunccallback,gpointer user_data );

  If you want to use gtk_toolbar_insert_item, the only additional parameter which must be specified is the position in which the item should be inserted, thus:


GtkWidget *gtk_toolbar_insert_item( GtkToolbar*toolbar,const char*text,
const char*tooltip_text,const char*tooltip_private_text,GtkWidget *icon,
GtkSignalFunccallback,gpointer user_data,gint position );

  To simplify adding spaces between toolbar items, you may use the following functions:


void gtk_toolbar_append_space( GtkToolbar *toolbar );
void gtk_toolbar_prepend_space( GtkToolbar *toolbar );
void gtk_toolbar_insert_space( GtkToolbar *toolbar,gintposition );

  While the size of the added space can be set globally for a whole toolbar with the function:


void gtk_toolbar_set_space_size( GtkToolbar *toolbar,gintspace_size) ;

  If it's required, the orientation of a toolbar and its style can be changed "on the fly" using the following functions:


void gtk_toolbar_set_orientation( GtkToolbar *toolbar,
GtkOrientationorientation );
void gtk_toolbar_set_style( GtkToolbar*toolbar,
GtkToolbarStylestyle );
void gtk_toolbar_set_tooltips( GtkToolbar *toolbar,gintenable );

  Where orientation is one of GTK_ORIENTATION_HORIZONTAL or GTK_ORIENTATION_VERTICAL. The style is used to set appearance of the toolbar items by using one of GTK_TOOLBAR_ICONS, GTK_TOOLBAR_TEXT, or GTK_TOOLBAR_BOTH.

  To show some other things that can be done with a toolbar, let's take the following program (we'll interrupt the listing with some additional explanations):


#include <gtk/gtk.h>
#include "gtk.xpm"
/* This function is connected to the Close button or
 * closing the window from the WM */
gint delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
{
gtk_main_quit ();
return(FALSE);
}

  The above beginning seems for sure familiar to you if it's not your first GTK program. There is one additional thing though, we include a nice XPM picture to serve as an icon for all of the buttons.


GtkWidget* close_button; /* This button will emit signal to close
* application */
GtkWidget* tooltips_button; /* to enable/disable tooltips */
GtkWidget* text_button,
 * icon_button,
 * both_button; /* radio buttons for toolbar style */
GtkWidget* entry; /* a text entry to show packing any widget into
 * toolbar */


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



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

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