void cut_text(Control *c); /* cut selection to clipboard */ void copy_text(Control *c); /* copy selection to clipboard */ void clear_text(Control *c); /* clear selection */ void paste_text(Control *c); /* paste over selection */ void insert_text(Control *c, char *text); void select_text(Control *c, long start, long end); void text_selection(Control *c, long *start, long *end); void set_control_text(Control *c, char *newtext); char *get_control_text(Control *c);
The following text editing functions will work with any textbox or field:
The cut_text function cuts whatever text is currently selected from the specified textbox, and places the text into the clipboard, while copy_text copies the text to the clipboard without deleting the text. To delete the currently selected text without transferring it to the clipboard, clear_text can be used.
The paste_text function pastes the text in the clipboard into the specified textbox, deleting any currently selected text in the process.
The insert_text 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 this function 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 select_text. 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 select_text(-1,-1) moves the insertion point to the end of the textbox, select_text(0,0) moves the insertion point to the start, and select_text(0,-1) selects all the text.
What text is currently selected can be found by use of the text_selection function. It returns the start and end-points of any selected text in the supplied long integer pointers.
Many controls have associated with them a text string, (e.g. buttons, text fields, labels, windows). This text string can be changed using set_control_text and can be found using get_control_text. The string returned from get_control_text is a read-only string! Do not modify it or free it.