📄 sec-toolbar.html
字号:
<HTML><HEAD><TITLE>Toolbar</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Container Widgets"HREF="ch-containerwidgets.html"><LINKREL="PREVIOUS"TITLE="Button Boxes"HREF="sec-buttonboxes.html"><LINKREL="NEXT"TITLE="Notebooks"HREF="sec-notebooks.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%"> <tr> <td bgcolor="#FFFFFF" valign=top nowrap> <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A> <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR> </td> <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-buttonboxes.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 10. Container Widgets</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-notebooks.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-TOOLBAR">10.11. Toolbar</A></H1><P>Toolbars are usually used to group some number of widgets in order tosimplify customization of their look and layout. Typically a toolbarconsists of buttons with icons, labels and tooltips, but any otherwidget can also be put inside a toolbar. Finally, items can bearranged horizontally or vertically and buttons can be displayed withicons, labels, or both.</P><P>Creating a toolbar is (as one may already suspect) done with thefollowing function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_toolbar_new( GtkOrientation orientation, GtkToolbarStyle style );</PRE></TD></TR></TABLE><P>where orientation may be one of:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> GTK_ORIENTATION_HORIZONTAL GTK_ORIENTATION_VERTICAL</PRE></TD></TR></TABLE><P>and style one of:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> GTK_TOOLBAR_TEXT GTK_TOOLBAR_ICONS GTK_TOOLBAR_BOTH</PRE></TD></TR></TABLE><P>The style applies to all the buttons created with the `item' functions(not to buttons inserted into toolbar as separate widgets).</P><P>After creating a toolbar one can append, prepend and insert items(that means simple text strings) or elements (that means any widgettypes) into the toolbar. To describe an item we need a label text, atooltip text, a private tooltip text, an icon for the button and acallback function for it. For example, to append or prepend an itemyou may use the following functions:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_toolbar_append_item( GtkToolbar *toolbar, const char *text, const char *tooltip_text, const char *tooltip_private_text, GtkWidget *icon, GtkSignalFunc callback, gpointer user_data );GtkWidget *gtk_toolbar_prepend_item( GtkToolbar *toolbar, const char *text, const char *tooltip_text, const char *tooltip_private_text, GtkWidget *icon, GtkSignalFunc callback, gpointer user_data );</PRE></TD></TR></TABLE><P>If you want to use gtk_toolbar_insert_item, the only additionalparameter which must be specified is the position in which the itemshould be inserted, thus:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_toolbar_insert_item( GtkToolbar *toolbar, const char *text, const char *tooltip_text, const char *tooltip_private_text, GtkWidget *icon, GtkSignalFunc callback, gpointer user_data, gint position );</PRE></TD></TR></TABLE><P>To simplify adding spaces between toolbar items, you may use thefollowing functions:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_toolbar_append_space( GtkToolbar *toolbar );void gtk_toolbar_prepend_space( GtkToolbar *toolbar );void gtk_toolbar_insert_space( GtkToolbar *toolbar, gint position );</PRE></TD></TR></TABLE><P>While the size of the added space can be set globally for awhole toolbar with the function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_toolbar_set_space_size( GtkToolbar *toolbar, gint space_size) ;</PRE></TD></TR></TABLE><P>If it's required, the orientation of a toolbar and its style can bechanged "on the fly" using the following functions:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_toolbar_set_orientation( GtkToolbar *toolbar, GtkOrientation orientation );void gtk_toolbar_set_style( GtkToolbar *toolbar, GtkToolbarStyle style );void gtk_toolbar_set_tooltips( GtkToolbar *toolbar, gint enable );</PRE></TD></TR></TABLE><P>Where <TTCLASS="LITERAL">orientation</TT> is one of <TTCLASS="LITERAL">GTK_ORIENTATION_HORIZONTAL</TT> or<TTCLASS="LITERAL">GTK_ORIENTATION_VERTICAL</TT>. The <TTCLASS="LITERAL">style</TT> is used to setappearance of the toolbar items by using one of<TTCLASS="LITERAL">GTK_TOOLBAR_ICONS</TT>, <TTCLASS="LITERAL">GTK_TOOLBAR_TEXT</TT>, or<TTCLASS="LITERAL">GTK_TOOLBAR_BOTH</TT>.</P><P>To show some other things that can be done with a toolbar, let's takethe following program (we'll interrupt the listing with someadditional explanations):</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">#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);}</PRE></TD></TR></TABLE><P>The above beginning seems for sure familiar to you if it's not your firstGTK program. There is one additional thing though, we include a nice XPMpicture to serve as an icon for all of the buttons.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget* close_button; /* This button will emit signal to close * application */GtkWidget* tooltips_button; /* to enable/disable tooltips */GtkWidget* text_button,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -