📄 ch-textwidget.html
字号:
<HTML><HEAD><TITLE>Text Widget</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="PREVIOUS"TITLE="Item Factory Example"HREF="sec-itemfactoryexample.html"><LINKREL="NEXT"TITLE="Text Manipulation"HREF="sec-textmanipulation.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="CHAPTER"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-itemfactoryexample.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-textmanipulation.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="CH-TEXTWIDGET">Chapter 15. Text Widget</A></H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT>15.1. <AHREF="ch-textwidget.html#SEC-CREATINGANDCONFIGURINGATEXTBOX">Creating and Configuring a Text box</A></DT><DT>15.2. <AHREF="sec-textmanipulation.html">Text Manipulation</A></DT><DT>15.3. <AHREF="sec-keyboardshortcuts.html">Keyboard Shortcuts</A></DT><DT>15.4. <AHREF="sec-agtktextexample.html">A GtkText Example</A></DT></DL></DIV><P>The Text widget allows multiple lines of text to be displayed andedited. It supports both multi-colored and multi-font text, allowingthem to be mixed in any way we wish. It also has a wide set of keybased text editing commands, which are compatible with Emacs.</P><P>The text widget supports full cut-and-paste facilities, including theuse of double- and triple-click to select a word and a whole line,respectively.</P><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-CREATINGANDCONFIGURINGATEXTBOX">15.1. Creating and Configuring a Text box</A></H1><P>There is only one function for creating a new Text widget.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_text_new( GtkAdjustment *hadj, GtkAdjustment *vadj );</PRE></TD></TR></TABLE><P>The arguments allow us to give the Text widget pointers to Adjustmentsthat can be used to track the viewing position of the widget. PassingNULL values to either or both of these arguments will cause thegtk_text_new function to create its own.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_text_set_adjustments( GtkText *text, GtkAdjustment *hadj, GtkAdjustment *vadj );</PRE></TD></TR></TABLE><P>The above function allows the horizontal and vertical adjustments of atext widget to be changed at any time.</P><P>The text widget will not automatically create its own scrollbars whenthe amount of text to be displayed is too long for the displaywindow. We therefore have to create and add them to the display layoutourselves.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> vscrollbar = gtk_vscrollbar_new (GTK_TEXT(text)->vadj); gtk_box_pack_start(GTK_BOX(hbox), vscrollbar, FALSE, FALSE, 0); gtk_widget_show (vscrollbar);</PRE></TD></TR></TABLE><P>The above code snippet creates a new vertical scrollbar, and attachesit to the vertical adjustment of the text widget, <TTCLASS="LITERAL">text</TT>. It thenpacks it into a box in the normal way.</P><P>Note, currently the Text widget does not support horizontalscrollbars.</P><P>There are two main ways in which a Text widget can be used: to allowthe user to edit a body of text, or to allow us to display multiplelines of text to the user. In order for us to switch between thesemodes of operation, the text widget has the following function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_text_set_editable( GtkText *text, gint editable );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">editable</TT> argument is a TRUE or FALSE value that specifieswhether the user is permitted to edit the contents of the Textwidget. When the text widget is editable, it will display a cursor atthe current insertion point.</P><P>You are not, however, restricted to just using the text widget inthese two modes. You can toggle the editable state of the text widgetat any time, and can insert text at any time.</P><P>The text widget wraps lines of text that are too long to fit onto asingle line of the display window. Its default behaviour is to breakwords across line breaks. This can be changed using the next function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_text_set_word_wrap( GtkText *text, gint word_wrap );</PRE></TD></TR></TABLE><P>Using this function allows us to specify that the text widget shouldwrap long lines on word boundaries. The <TTCLASS="LITERAL">word_wrap</TT> argument is aTRUE or FALSE value.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-itemfactoryexample.html"><<< Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-textmanipulation.html">Next >>></A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Item Factory Example</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"> </TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Text Manipulation</TD></TR></TABLE></DIV> </td> </tr></table> </td> </tr></table></body></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -