void cuttext(textbox t); /* cut selection to clipboard */ void copytext(textbox t); /* copy selection to clipboard */ void cleartext(textbox t); /* clear selection */ void pastetext(textbox t); /* paste clipboard over selection */ void inserttext(textbox t, char *text); void selecttext(textbox t, long start, long end); void textselection(textbox t, long *start, long *end); void settext(control c, char *newtext); /* find contents */ char *gettext(control c); /* change contents */
The following text editing functions will work with any textbox or a field:
The cuttext function cuts whatever text is currently selected from the specified textbox, and places the text into the clipboard, while copytext copies the text to the clipboard without deleting the text.
To delete the currently selected text without transferring it to the clipboard, cleartext can be used.
The pastetext function pastes the text in the clipboard into the specified textbox, deleting any currently selected text in the process.
The inserttext function inserts a specified text string after the insertion point in a textbox. The insertion point is then moved to be after the newly inserted text. Repeated use of inserttext will thus behave the same as if the user had typed text into the textbox.
The current text selection can be changed by use of selecttext. The start and end locations are measured from zero being before the first character in the textbox. The number negative one has special meaning: it refers to the location after the last character in the textbox. Hence selecttext(-1,-1) moves the insertion point to the end of the textbox, selecttext(0,0) moves the insertion point to the start, and selecttext(0,-1) selects all the text.
What text is currently selected can be found by use of the textselection function. It returns the start and end-points of any selected text in the supplied long integer pointers. (NB: in Python this function actually returns a tuple instead of taking pointers.)
Many controls have associated with them a text string, (e.g. buttons, text fields, labels, windows). This text string can be changed using settext and can be found using gettext. The string returned from gettext is a read-only string! Do not modify it or free it.