1 <sect1 id="Text_Functions">
2 <title>Text Functions</title>
4 <!-- Text Functions -->
8 The following functions are provided as convenience routines for use with
9 the Text widget. Although many of these actions can be performed by
10 modifying resources, these interfaces are frequently more efficient.
14 These data structures are defined in the Text widget's public header file,
15 <X11/Xaw/Text.h>.
19 <!-- .IN "XawTextPosition" "" "@DEF@" -->
20 typedef long XawTextPosition;
25 Character positions in the Text widget begin at 0 and end at n, where
26 n is the number of characters in the Text source widget.
30 <!-- .IN "XawTextBlock" "" "@DEF@" -->
31 <literallayout class="monospaced">
32 <!-- .TA .5i 1.5i 2.25i -->
33 <!-- .ta .5i 1.5i 2.25i -->
35 int <emphasis remap='I'>firstPos</emphasis>;
36 int <emphasis remap='I'>length</emphasis>;
37 char *<emphasis remap='I'>ptr</emphasis>;
38 unsigned long <emphasis remap='I'>format</emphasis>;
39 } XawTextBlock, *XawTextBlockPtr;
44 <!-- .IN "XawTextBlockPtr" "" -->
48 <emphasis remap='I'>firstPos</emphasis>
52 The first position, or index, to use within the <emphasis remap='I'>ptr</emphasis> field.
53 The value is commonly zero.
59 <emphasis remap='I'>length</emphasis>
63 The number of characters to be used from the <emphasis remap='I'>ptr</emphasis> field.
64 The number of characters used is commonly the number of characters
65 in <emphasis remap='I'>ptr</emphasis>, and must not be greater than the length of the string
66 in <emphasis remap='I'>ptr</emphasis>.
72 <emphasis remap='I'>ptr</emphasis>
76 Contains the string to be referenced by the Text widget.
82 <emphasis remap='I'>format</emphasis>
86 This flag indicates whether the data pointed to by <function>ptr</function> is char
87 or wchar_t. When the associated widget has <function>international</function> set
88 to <function>false</function> this field must be XawFmt8Bit. When the associated
89 widget has <function>international</function> set to <function>true</function> this field must be
90 either XawFmt8Bit or XawFmtWide.
99 Note: Previous versions of Xaw used
100 <function>FMT8BIT ,</function>
101 which has been retained for backwards compatibility. <function>FMT8BIT</function> is
102 deprecated and will eventually be removed from the implementation.
105 <sect2 id="Selecting_Text">
106 <title>Selecting Text</title>
109 To select a piece of text, use
110 <function>XawTextSetSelection : </function>
111 <!-- .IN "XawTextSetSelection" "" "@DEF@" -->
114 <funcdef>void<function> XawTextSetSelection</function></funcdef>
115 <paramdef>Widget<parameter> w</parameter></paramdef>
116 <paramdef>XawTextPositionleft,<parameter> right</parameter></paramdef>
123 <emphasis remap='I'>w</emphasis>
127 Specifies the Text widget.
133 <emphasis remap='I'>left</emphasis>
137 Specifies the character position at which the selection begins.
143 <emphasis remap='I'>right</emphasis>
147 Specifies the character position at which the selection ends.
155 See section 5.4 for a description of <function>XawTextPosition</function>. <!-- xref -->
156 If redisplay is enabled, this function highlights the text and
157 makes it the <function>PRIMARY</function> selection. This function does not have any
158 effect on <function>CUT_BUFFER0</function>.
164 <sect2 id="Unhighlighting_Text">
165 <title>Unhighlighting Text</title>
168 To unhighlight previously highlighted text in a widget, use
169 <function>XawTextUnsetSelection</function>:
170 <!-- .IN "XawTextUnsetSelection" "" "@DEF@" -->
173 <funcdef>void<function> XawTextUnsetSelection</function></funcdef>
174 <paramdef>Widget<parameter> w</parameter></paramdef>
181 <emphasis remap='I'>w</emphasis>
185 Specifies the Text widget.
192 <sect2 id="Getting_Current_Text_Selection">
193 <title>Getting Current Text Selection</title>
196 To retrieve the text that has been selected by this
197 text widget use <function>XawTextGetSelectionPos</function>:
198 <!-- .IN "XawTextGetSelectionPos" "" "@DEF@" -->
201 <funcdef>void<function> XawTextGetSelectionPos</function></funcdef>
202 <paramdef>Widget<parameter> w</parameter></paramdef>
203 <paramdef>XawTextPosition*begin_return,<parameter> *end_return</parameter></paramdef>
210 <emphasis remap='I'>w</emphasis>
214 Specifies the Text widget.
220 <emphasis remap='I'>begin_return</emphasis>
224 Returns the beginning of the text selection.
230 <emphasis remap='I'>end_return</emphasis>
234 Returns the end of the text selection.
242 See section 5.4 for a description of <function>XawTextPosition</function>. <!-- xref -->
243 If the returned values are equal, no text is currently selected.
246 <sect2 id="Replacing_Text">
247 <title>Replacing Text</title>
250 To modify the text in an editable Text widget use <function>XawTextReplace</function>:
251 <!-- .IN "XawTextReplace" "" "@DEF@" -->
254 <funcdef>int<function> XawTextReplace</function></funcdef>
255 <paramdef>Widget<parameter> w</parameter></paramdef>
256 <paramdef>XawTextPositionstart,<parameter> end</parameter></paramdef>
257 <paramdef>XawTextBlock<parameter> *text</parameter></paramdef>
264 <emphasis remap='I'>w</emphasis>
268 Specifies the Text widget.
274 <emphasis remap='I'>start</emphasis>
278 Specifies the starting character position of the text replacement.
284 <emphasis remap='I'>end</emphasis>
288 Specifies the ending character position of the text replacement.
294 <emphasis remap='I'>text</emphasis>
298 Specifies the text to be inserted into the file.
306 This function will not
307 be able to replace text in read-only text widgets. It will also only
308 be able to append text to an append-only text widget.
312 See section 5.4 for a description of <function>XawTextPosition</function> and <!-- xref -->
313 <function>XawTextBlock</function>.
317 This function may return the following values:
321 <function>XawEditDone</function>
325 <!-- .IN "XawEditDone" "" -->
326 The text replacement was successful.
332 <function>XawPositionError</function>
336 <!-- .IN "XawPositionError" "" -->
337 The edit mode is <function>XawtextAppend</function> and <function>start</function> is not the position of
338 the last character of the source.
344 <function>XawEditError</function>
348 <!-- .IN "XawEditError" "" -->
349 Either the Source was read-only or the range to be deleted is larger
350 than the length of the Source.
359 The <function>XawTextReplace</function> arguments <function>start</function> and
360 <emphasis remap='I'>end</emphasis> represent the text source character positions for the
361 existing text that is to be replaced by the text in the text block.
362 The characters from <emphasis remap='I'>start</emphasis> up to
363 but not including <emphasis remap='I'>end</emphasis> are deleted, and the characters
364 specified on the text block are inserted in their place. If
365 <emphasis remap='I'>start</emphasis> and <emphasis remap='I'>end</emphasis> are equal, no text is deleted and the new
366 text is inserted after <emphasis remap='I'>start</emphasis>.
369 <sect2 id="Searching_for_Text">
370 <title>Searching for Text</title>
373 To search for a string in the Text widget, use
374 <function>XawTextSearch</function>:
375 <!-- .IN "XawTextSearch" "" "@DEF@" -->
378 <funcdef>XawTextPosition<function> XawTextSearch</function></funcdef>
379 <paramdef>Widget<parameter> w</parameter></paramdef>
380 <paramdef>XawTextScanDirection<parameter> dir</parameter></paramdef>
381 <paramdef>XawTextBlock*<parameter> text</parameter></paramdef>
388 <emphasis remap='I'>w</emphasis>
392 Specifies the Text widget.
398 <emphasis remap='I'>dir</emphasis>
402 Specifies the direction to search in. Legal values are
403 <function>XawsdLeft</function> and <function>XawsdRight</function>.
409 <emphasis remap='I'>text</emphasis>
413 Specifies a text block structure that contains the text to search for.
421 See section 5.4 for a description of <function>XawTextPosition</function> and <function>XawTextBlock</function>. <!-- xref -->
422 The <function>XawTextSearch</function> function will begin at the insertion point
424 direction specified for a string that matches the one passed in
425 <emphasis remap='I'>text</emphasis>. If the string is found the location of the first
426 character in the string is returned. If the string could not be
427 found then the value <function>XawTextSearchError</function> is returned.
430 <sect2 id="Redisplaying_Text">
431 <title>Redisplaying Text</title>
434 To redisplay a range of characters, use <function>XawTextInvalidate</function>:
435 <!-- .IN "XawTextInvalidate" "" "@DEF@" -->
438 <funcdef>void<function> XawTextInvalidate</function></funcdef>
439 <paramdef>Widget<parameter> w</parameter></paramdef>
440 <paramdef>XawTextPositionfrom,<parameter> to</parameter></paramdef>
447 <emphasis remap='I'>w</emphasis>
451 Specifies the Text widget.
457 <emphasis remap='I'>from</emphasis>
461 Specifies the start of the text to redisplay.
467 <emphasis remap='I'>to</emphasis>
471 Specifies the end of the text to redisplay.
479 See section 5.4 for a description of <function>XawTextPosition</function>. <!-- xref -->
480 The <function>XawTextInvalidate</function>
481 function causes the specified range of characters to be redisplayed
482 immediately if redisplay is enabled or the next time that redisplay is
488 To enable redisplay, use <function>XawTextEnableRedisplay</function>:
489 <!-- .IN "XawTextEnableRedisplay" "" "@DEF@" -->
492 <funcdef>void<function> XawTextEnableRedisplay</function></funcdef>
493 <paramdef>Widget<parameter> w</parameter></paramdef>
500 <emphasis remap='I'>w</emphasis>
504 Specifies the Text widget.
512 The <function>XawTextEnableRedisplay</function> function flushes any changes due to
513 batched updates when <function>XawTextDisableRedisplay</function>
514 was called and allows future changes to be reflected immediately.
519 To disable redisplay while making several changes, use
520 <function>XawTextDisableRedisplay</function>.
521 <!-- .IN "XawTextDisableRedisplay" "" "@DEF@" -->
524 <funcdef>void<function> XawTextDisableRedisplay</function></funcdef>
525 <paramdef>Widget<parameter> w</parameter></paramdef>
532 <emphasis remap='I'>w</emphasis>
536 Specifies the Text widget.
544 The <function>XawTextDisableRedisplay</function> function causes all changes to be
545 batched until either <function>XawTextDisplay</function> or <function>XawTextEnableRedisplay</function>
551 To display batched updates, use <function>XawTextDisplay</function>:
552 <!-- .IN "XawTextDisplay" "" "@DEF@" -->
555 <funcdef>void<function> XawTextDisplay</function></funcdef>
556 <paramdef>Widget<parameter> w</parameter></paramdef>
563 <emphasis remap='I'>w</emphasis>
567 Specifies the Text widget.
575 The <function>XawTextDisplay</function> function forces any accumulated updates to be
579 <sect2 id="Resources_Convenience_Routines">
580 <title>Resources Convenience Routines</title>
583 To obtain the character position of the left-most character on the
584 first line displayed in the widget (the value of the
585 <function>displayPosition</function> resource), use <function>XawTextTopPosition</function>.
586 <!-- .IN "XawTextTopPosition" "" @DEF@" -->
589 <funcdef>XawTextPosition<function> XawTextTopPosition</function></funcdef>
590 <paramdef>Widget<parameter> w</parameter></paramdef>
597 <emphasis remap='I'>w</emphasis>
601 Specifies the Text widget.
610 To assign a new selection array to a text widget use
611 <function>XawTextSetSelectionArray</function>:
612 <!-- .IN "XawTextSetSelectionArray" "" "@DEF@" -->
615 <funcdef>void<function> XawTextSetSelectionArray</function></funcdef>
616 <paramdef>Widget<parameter> w</parameter></paramdef>
617 <paramdef>XawTextSelectType*<parameter> sarray</parameter></paramdef>
624 <emphasis remap='I'>w</emphasis>
628 Specifies the Text widget.
634 <emphasis remap='I'>sarray</emphasis>
638 Specifies a selection array as defined in the section called \fBText
639 Selections for Application Programmers\fP.
647 Calling this function is equivalent to setting the value of the
648 <function>selectionTypes</function> resource.
653 To move the insertion point to the specified source position, use
654 <function>XawTextSetInsertionPoint</function>:
655 <!-- .IN "XawTextSetInsertionPoint" "" "@DEF@" -->
658 <funcdef>void<function> XawTextSetInsertionPoint</function></funcdef>
659 <paramdef>Widget<parameter> w</parameter></paramdef>
660 <paramdef>XawTextPosition<parameter> position</parameter></paramdef>
667 <emphasis remap='I'>w</emphasis>
671 Specifies the Text widget.
677 <emphasis remap='I'>position</emphasis>
681 Specifies the new position for the insertion point.
689 See section 5.4 for a description of <function>XawTextPosition</function>. <!-- xref -->
690 The text will be scrolled vertically if necessary to make the line
691 containing the insertion point visible. Calling this function is
692 equivalent to setting the <function>insertPosition</function> resource.
697 To obtain the current position of the insertion point, use
698 <function>XawTextGetInsertionPoint</function>:
699 <!-- .IN "XawTextGetInsertionPoint" "" "@DEF@" -->
702 <funcdef>XawTextPosition<function> XawTextGetInsertionPoint</function></funcdef>
703 <paramdef>Widget<parameter> w</parameter></paramdef>
710 <emphasis remap='I'>w</emphasis>
714 Specifies the Text widget.
722 See section 5.4 for a description of <function>XawTextPosition</function>. <!-- xref -->
723 The result is equivalent to retrieving the value of the
724 <function>insertPosition</function> resource.
729 To replace the text source in the specified widget, use
730 <function>XawTextSetSource</function>:
731 <!-- .IN "XawTextSetSource" "" "@DEF@" -->
734 <funcdef>void<function> XawTextSetSource</function></funcdef>
735 <paramdef>Widget<parameter> w</parameter></paramdef>
736 <paramdef>Widget<parameter> source</parameter></paramdef>
737 <paramdef>XawTextPosition<parameter> position</parameter></paramdef>
744 <emphasis remap='I'>w</emphasis>
748 Specifies the Text widget.
754 <emphasis remap='I'>source</emphasis>
758 Specifies the text source object.
764 <emphasis remap='I'>position</emphasis>
768 Specifies character position that will become the upper left hand corner
769 of the displayed text. This is usually set to zero.
777 See section 5.4 for a description of <function>XawTextPosition</function>. <!-- xref -->
778 A display update will be performed if redisplay is enabled.
783 To obtain the current text source for the specified widget, use
784 <function>XawTextGetSource</function>:
785 <!-- .IN "XawTextGetSource" "" "@DEF@" -->
788 <funcdef>Widget<function> XawTextGetSource</function></funcdef>
789 <paramdef>Widget<parameter> w</parameter></paramdef>
796 <emphasis remap='I'>w</emphasis>
800 Specifies the Text widget.
808 This function returns the text source that this Text widget is currently
814 To enable and disable the insertion point, use
815 <function>XawTextDisplayCaret</function>:
816 <!-- .IN "XawTextDisplayCaret" "" "@DEF@" -->
819 <funcdef>void<function> XawTextDisplayCaret</function></funcdef>
820 <paramdef>Widget<parameter> w</parameter></paramdef>
821 <paramdef>Boolean<parameter> visible</parameter></paramdef>
828 <emphasis remap='I'>w</emphasis>
832 Specifies the Text widget.
838 <emphasis remap='I'>visible</emphasis>
842 Specifies whether or not the caret should be displayed.
850 If <function>visible</function> is <function>False</function> the insertion point will be disabled.
851 The marker is re-enabled either by setting <function>visible</function> to <function>True</function>, by
852 calling <function>XtSetValues</function>, or by executing the <function>display-caret</function>