Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 2372

mozart-1.4.0-1mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>7.1 Manipulating Text</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node37.html">- Up -</A></TD><TD><A href="node39.html#section.text.tags">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="section.text.widget"><H2><A name="section.text.widget">7.1 Manipulating Text</A></H2><P> Let us start with a very simple example where we want to display a given text in a text widget. <A href="node38.html#figure.text.started">Figure&nbsp;7.1</A> shows a program that does the job. </P><P> </P><DIV id="figure.text.started"><HR><P><A name="figure.text.started"></A></P><P> </P><DIV align="center"><IMG alt="" src="display.gif"></DIV><P> </P><DL class="anonymous"><DD class="code"><CODE>T={New&nbsp;Tk<SPAN class="keyword">.</SPAN>text&nbsp;tkInit(parent:W&nbsp;width:28&nbsp;height:5&nbsp;bg:white)}<BR>{T&nbsp;tk(insert&nbsp;<SPAN class="string">'end'</SPAN>&nbsp;<SPAN class="string">&quot;The&nbsp;quick&nbsp;brown&nbsp;fox&nbsp;jumps&nbsp;over&nbsp;the&nbsp;lazy&nbsp;dog.&quot;</SPAN>)}</CODE></DD></DL><P> </P><P class="caption"><STRONG>Figure&nbsp;7.1:</STRONG> Displaying text.</P><HR></DIV><P> </P><DIV class="apropos"><P class="margin">scanning</P><P> <A name="label305"></A> Similar to <A href="node28.html#section.widgets-2.listbox">listboxes</A>, a text widget supports scanning: The text can be scanned by pressing the second mouse button and moving the mouse pointer while the button is still being pressed. And of course, in the same way as canvas widgets scrollbars can be attached to a text widget. </P></DIV><DIV class="apropos"><P class="margin">text wrapping</P><P> <A name="label306"></A> The text is wrapped where word boundaries (that is, spaces) are not taken into account. Changing the wrapping such that word boundaries are preserved can be done as follows: </P><DL class="anonymous"><DD class="code"><CODE>{T&nbsp;tk(configure&nbsp;wrap:word)}</CODE></DD></DL><P> </P></DIV><DIV class="apropos" id="para.text.position"><P class="margin">positions</P><P> <A name="label308"></A> Positions in the displayed text can be referred to by <A name="label309"></A><EM>positions</EM>. A position can be denoted by a tickle <CODE>p(</CODE><CODE><I>L</I></CODE><CODE>&nbsp;</CODE><CODE><I>C</I></CODE><CODE>)</CODE>, where <CODE><I>L</I></CODE> gives the line (starting from one) and <CODE><I>C</I></CODE> the position in that line (also starting from zero). Positions also can take modifiers, for more details on this issue see <A href="../tcltk/TkCmd/text.htm"><KBD>text</KBD></A>. Another helpful position is <CODE><SPAN class="string">'end'</SPAN></CODE> which refers to the position after the last character. </P></DIV><DIV class="apropos"><P class="margin">getting text</P><P> <A name="label311"></A> Portions of the text can be retrieved. For example, </P><DL class="anonymous"><DD class="code"><CODE>{T&nbsp;tkReturnAtom(get&nbsp;p(1&nbsp;4)&nbsp;p(1&nbsp;9)&nbsp;$)}</CODE></DD></DL><P> returns the atom <CODE>quick</CODE>. </P></DIV><DIV class="apropos"><P class="margin">inserting text</P><P> <A name="label313"></A> Positions also specify where to insert text, for example </P><DL class="anonymous"><DD class="code"><CODE>{T&nbsp;tk(insert&nbsp;p(1&nbsp;4)&nbsp;<SPAN class="string">&quot;very&nbsp;very&nbsp;&quot;</SPAN>)}</CODE></DD></DL><P> inserts the text directly before quick. </P></DIV><DIV class="apropos"><P class="margin">deleting text</P><P> <A name="label315"></A> In the same way text can also be deleted. For example </P><DL class="anonymous"><DD class="code"><CODE>{T&nbsp;tk(delete&nbsp;p(1&nbsp;4)&nbsp;p(1&nbsp;14))}</CODE></DD></DL><P> deletes again the text <CODE><SPAN class="string">&quot;very&nbsp;very&nbsp;&quot;</SPAN></CODE>. </P></DIV><DIV class="apropos"><P class="margin">disabling input</P><P> <A name="label317"></A> We do not discuss here how to employ a text widget as a powerful editor, please see again <A href="../tcltk/TkCmd/text.htm"><KBD>text</KBD></A>. If you try to place a cursor inside the text widget and make some character strokes, you will notice that by default a text widget accepts input. To prevent a user from altering the text in a display only situation the widget can be configured as follows: </P><DL class="anonymous"><DD class="code"><CODE>{T&nbsp;tk(configure&nbsp;state:disabled)}</CODE></DD></DL><P> </P></DIV></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node37.html">- Up -</A></TD><TD><A href="node39.html#section.text.tags">Next &gt;&gt;</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~schulte/">Christian&nbsp;Schulte</A><BR><SPAN class="version">Version 1.4.0 (20090610)</SPAN></ADDRESS></BODY></HTML>