6 The fields Library

The fields library contains five advanced subpatterns of windowItem. These patterns are used for displaying movies and editable text fields (with and without scrolling facilities), and for scrolling a group of windowItems using scrollbars.

[2kb 255x114 GIF]

TextField is an alternative to the editText control with extended facilities for cut/copy/paste, selection handling, etc. TextField contains many attributes supporting many different text editing functions: changing text style, deleting and inserting text, etc. Furthermore, textField has an additional event onTextChanged which will be invoked each time the text contents have been changed.

A readonly textField can be implemented simply by further binding the onBeforeChange virtual and here specify false->allow.

TextField takes care of most interaction with the user and many applications using textField need not do anything else but extract the text contents of the textField instance at the appropriate time.

AbstractScroller is a subpattern of canvas and implements a scrolling facility for any windowItem type (specified through the contentsType virtual attribute). An abstractScroller contains two scrollbars (one vertical and one horizontal), and the windowItem will scroll according to the manipulations of these scrollbars.

TextEditor is a subpattern of abstractScroller (with contentsType further bound to textField) and is an alternative to textField, offering additional scrolling facilities. TextEditor is a full-fledged text editor with full editing and scrolling. No additional attributes are defined.

TextEditor takes care of most interaction with the user and many applications using textEditor need not do anything else but extract the text contents of the textEditor instance at the appropriate time.

Scroller is another subpattern of abstractScroller (with contentsType further bound to canvas) that can scroll all windowItems attached to the canvas.

MovieField is intended for displaying video (not implemented yet).

6.1 Using the fields Library

Remember that in order to utilize this extension to Lidskjalv, the fragment fields must be included as follows:

ORIGIN '~beta/guienv/guienv';
INCLUDE '~beta/guienv/fields'
--- program: descriptor ---
guienv(# te: @textEditor;
         ...
      do ...
         ... -> te.contents.selection;
         ...
      #)

6.2 Examples of Use of the fields Fragment

This demo program illustrates the facilities for constructing standard text editors.

Program 5: texteditor.bet

ORIGIN '~beta/guienv/fields';
INCLUDE '~beta/guienv/stddialogs';
INCLUDE '~beta/basiclib/file';
(* This demo shows how to build a simple texteditor. *)
--- program: descriptor ---
guienv
(# theWindow: @window
     (# menubarType::
          (# fileMenu: @menu
               (# textFile: @file;
                  openItem: @menuItem
                    (# eventHandler::
                         (# onSelect::
                              (# theText: @StyledText; path: ^text;
                              do theWindow[] -> fileSelectionDialog -> path[];
                                 (if path[]<>NONE then
                                     path[] -> textFile.name;
                                     textFile.openRead;
                                     textFile.scan
                                     (# while:: (# do true->value #);
                                     do ch -> theText.put
                                     #);
                                     theText[]
                                       ->theTextEditor.contents.contents;
                                     textFile.close
                                 if)
                         #)#);
                       open:: (# do 'Open' -> name #)
                    #);
                  saveItem: @menuItem
                    (# eventHandler::
                         (# onSelect::
                              (# theText: @Text; tempName: ^text;
                              do textFile.name -> tempName[];
                                 (if tempName.length>0 then
                                     textFile.openWrite;
                                     theTextEditor.contents.contents
                                       ->textFile.puttext;
                                     textFile.close
                                 if)
                         #)#);
                       open:: 
                         (# do 'Save' -> name #)
                    #);
                  quitItem: @menuItem
                    (# eventHandler:: 
                         (# onSelect:: (# do terminate #) #);
                       open:: 
                         (# do 'Quit' -> name #)
                    #);
                  open::
                    (#
                    do 'File' -> name;
                       openItem.open; openItem[] -> append;
                       saveItem.open; saveItem[] -> append;
                       quitItem.open; quitItem[] -> append
               #)#);
             open:: 
               (# do fileMenu.open; fileMenu[] -> append #)
          #); (* menubarType *)
        eventhandler::
          (# onAboutToClose:: (# do terminate #) #);
        thetextEditor: @textEditor
          (# open:: 
               (# 
               do 'TextEditor' -> title;
                  theWindow.size -> size;
                  true -> bindBottom -> bindRight
               #)
          #);
        open::
          (#
          do 'thetextEditor' -> title;
             (400,400) -> size;
             thetextEditor.open
          #)
     #)
do theWindow.open
#)
[24kb 398x450 GIF]


Lidskjalv: User Interface Framework - Reference Manual
© 1994-2002 Mjølner Informatics
[Modified: Friday October 27th 2000 at 14:56]