Lidskjalv offers facilities for defining more advanced fields than the above mentioned controls. These facilities include window items as two different text editing fields (textField and textEditor). These patterns are subpatterns of windowItem and inherits as such all its facilities.
TextField and textEditor are both advanced text editors offering the usual text editing facilities, such as fonts, cut/copy/paste, selections, etc. along with simple text manipulation functions. All event handling is automatically taken care of by the patterns. TextEditor is only special by offering scrolling facilities.
TextField handles text selection through the selection attribute. Selection.start contains the character position of the first character in the selection and selection.end contains the character position of the last character in the selection. If selection.start = selection.end, then nothing is selected, and selection.start identifies the position of the text cursor. Selection.contents returns the text in the selection. ScrollIntoView will make sure that the current selection is visible.
The text editing facilities are cut, copy and paste, that implements the usual cut/copy/paste functionality. Insert takes a text as parameter, and inserts it immediately before the current selection, and delete deletes the text of the current selection.
To enable scanning the entire text in the text field, the scanText operation is defined. ScanText is a control pattern that takes two positions as parameters, and iterates over the characters in the text editor between the two positions. During the scan, ch will contain the current character in the text.
The text contents of the text field is accessed through the contents attribute that can be used for getting a copy of the current text in the text field.
The simplest possible 'Hello World' textField can be specified as follows:
ORIGIN '~beta/guienv/guienv'; INCLUDE '~beta/guienv/fields' --- program: descriptor --- guienv (# textWindow: @window (# txtField: @textField (# open:: (# t: @styledText; do (0, 0)->position; (300, 100)->size; 'Hello World!'->t; t[]->contents #) #); eventhandler:: (# onAboutToClose:: (# do terminate #) #); open:: (# do (20, 100)->position; (300, 100)->size; 'textField'->title; txtField.open #) #); do textWindow.open #)
This will create a textField at position (20, 100) and with size (300, 100). The initial contents of the textField is 'Hello World!'. All usual text editing facilities will be available in the editor:
By replacing textField by textEditor and subtracting (15,15) from the size of the myTextField will result in a window with at text editor with scrolling facilities. The reason for subtracting (15, 15) from the size of the editor field is to make room for the scrollbars at the right and bottom of the window.
ORIGIN '~beta/guienv/guienv'; INCLUDE '~beta/guienv/fields' --- program: descriptor --- guienv (# textWindow: @window (# txtEdit: @textEditor (# open:: (# t: @styledText; do (-1, -1)->position; (287, 87)->size; 'Hello World!'->t; t[]->contents.contents; true -> bindRight; true -> bindBottom; #) #); eventhandler:: (# onAboutToClose:: (# do terminate #) #); open:: (# do (20, 100)->position; (285, 85)->size; 'textEditor'->title; txtEdit.open #) #); do textWindow.open #)
Note, that the only visible difference, compared with the previous textField example is that a text editor automatically has both vertical and horizontal scroll bars.
Lidskjalv: User Interface Framework - Tutorial | © 1995-2002 Mjølner Informatics |
[Modified: Friday October 27th 2000 at 14:56]
|