9.2 Control Items

Control items are the bread and butter of dialogs. Control items exists in seven different forms (all subpatterns of windowItem), namely text labels, text fields (editable), buttons, check boxes, radio boxes, icons and pictures. These control items are defined as subpatterns of the control pattern.

The inheritance tree of controls in the controls library is:

[3kb 420x167 GIF]

To illustrate the facilities, we have included the Macintosh graphical elements associated with these classes. Naturally, the graphical elements will appear differently on the Motif and Win32 platforms:

Control pattern name

Image

Description

scrollbar

[1kb 96x19 GIF]

Used for various scrolling purposes.

staticText

[919 bytes 50x19 GIF]

Used to specify permanent text in the dialog (usually explanatory text).

editText

[946 bytes 38x26 GIF]

Used to allow the user to enter some text.

pushButton

[1kb 74x54 GIF]

A button is used to specify some actions to be taken.

optionButton

[1011 bytes 120x18 GIF]

Used to specify a button with associated pop-up menu.

checkBox

[1kb 135x29 GIF]

A check box is usually used together with other check boxes to present the user with a group of non-exclusive options.

radioButton

[1kb 75x27 GIF]

A radio box is usually used together with other radio boxes to present the user with a group of exclusive options.

iconButton

[1007 bytes 43x35 GIF]

An icon is used to show a minor picture in the dialog.

The control pattern is a subpattern of windowItem and inherits as such all its facilities (size, position, event handling, etc.). The actions to be associated with a control must be specified in further bindings of e.g. the virtual event pattern onMouseDown. Control defines some other facilities that can be ignored for most Lidskjalv applications.

Scrollbar defines various attributes for controlling the scrollbar (scrollAmount, maxValue and value). Besides the eventhandler, a new event patterns are defined: onThumbMoved. OnThumbMoved is invoked when the user moved the scroll thumb. The orientation (vertical or horizontal) is controlled through the vertical attribute, such that true->vertical specifies the scrollbar to be vertical (horizontal for false). Finally, the length of the scrollbar is controlled by the length attribute.

Button is also a subpattern of control and is the superpattern for the rest of the controls. The attributes of button are controlling the label (text and text style), associated with all buttons.

PushButton and staticText are simple subpatterns of button. IconButton is another simple subpattern of button, only defining one new attribute showLabel for controlling whether the label should be shown or not.

EditText is implementing a one-line text editor to be used for simple text specifications (file names etc.) The text style of the text is controlled by the style attribute, and the contents of the editText can be manipulated through the contents attribute. That is, if T is a text, and ET is a editText, then T[]-> ET.contents sets the text shown in the editText control to the contents of T (i.e. setting the initial contents), and ET.contents->T[] copies the contents of the editText control into T (i.e. reading the user input).

OptionButton defines a field which will pop-up a menu in response to the user pressing the mouse button on top of the field. The attributes of optionButton controls the associated menu and the currently selected menu item (shown inside the field).

ToggleButton is the common superpattern for the RadioButton and CheckBox controls. ToggleButton controls a binary state. A series of RadioButtons are used for specifying a set of exclusive options, and one or more checkBoxes are used for specifying a set of non-exclusive options.

Finally, one of the buttons in the window can be specified to function as a default button (i.e. be activated by pressing carriage return) by entering a reference to it to defaultButton.

The following example illustrates the use of controls:

Program 19: dialog.bet

ORIGIN '~beta/guienv/guienv';
INCLUDE '~beta/guienv/controls'
--- program: descriptor ---
guienv
(# authorName: @text;
   isReport: @boolean;
   theDialog: @window 
     (# cTitleLabel: @staticText 
          (# open:: 
               (# 
               do (10, 10)->position; (95,25)->size;
                  'Title: '->label
          #) #);
        cTitle: @editText 
          (# open::
               (# do (115, 10)->position; (150,25)->size #)
          #);
        cAuthorLabel: @staticText 
          (# open:: 
               (# 
               do (10, 40)->position; (95,25)->size;
                  'Author: '->label
          #) #);
        cAuthor: @editText 
          (# open:: 
               (# do (115, 40)->position; (150,25)->size #)
          #);
        cReport: @checkBox 
          (# open:: 
               (# 
               do (10, 70)->position;  (100,25)->size;
                  'Report'->label
               #);
             eventhandler:: 
               (# onMouseUp:: (# do not state->state #) #);
          #);
        cCancel: @pushButton
          (# open:: 
               (# 
               do (115, 70)->position; (80,25)->size;
                  'Cancel'->label
               #);
             eventhandler:: 
               (# onMouseUp:: (# do theDialog.close #) #)
          #);
        cOk: @pushButton
          (# open:: 
               (# 
               do (115+150-30, 70)->position; (30,25)->size; 
                  'OK'->label
               #);
             eventhandler:: 
               (# onMouseUp:: 
                    (# 
                    do (* store values, then *)
                       theDialog.close
               #) #)
          #);
        eventhandler::
          (# onAboutToClose:: (# do terminate #) #);
        open:: 
          (# 
          do (40,40)->position; (275,100)->size;
             'dialog'->title;
             cOk.open; cCancel.open;
             cTitleLabel.open; cTitle.open;
             cAuthorLabel.open; cAuthor.open;
             cReport.open;
             cOk[]->defaultButton
          #)
     #)
do theDialog.open;
   theDialog.showModal
#)

Program 20: screendump
(Windows NT)

[7kb 213x96 GIF]

This defines a dialog with two buttons, two editable text fields, two static text fields, and one check box (all enabled).


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