Summary:
See also: Presentation Styles, Window class, Form class, Flow Control, Forms, Input Array, Display Array, Record Input, Construct.
Programs manipulate "Window" and "Form" objects to define display areas for interactive instructions like INPUT ARRAY, DISPLAY ARRAY, INPUT and CONSTRUCT. When an interactive instruction takes control, it uses the Form associated with the current window.
Windows are created from programs; they define a display context for sub-elements like forms, ring menus, message and error lines. A window can contain only one form at a time.
When using a character terminal, windows are displayed as fixed-size boxes, at a given line and column position, with a given width and height. When using a graphical front end, windows are displayed as independent resizable windows by default. This behavior is needed to create real graphical applications, but it breaks the old-mode layout implementations.
When the runtime system starts a program, it creates a default window named SCREEN. This default window can be used as another window (it can hold a Ring Menu and a Form), but it can also be closed, with CLOSE WINDOW SCREEN.
A program creates a window with the OPEN WINDOW instruction, which also defines the window identifier. The program destroys a Window with the CLOSE WINDOW instruction. One or more windows can be displayed concurrently, but there can be only one current Window. You can use the CURRENT WINDOW instruction to make a specific window current.
When opening a window, the window style is used to specify the type and the decoration of the window.
You can also use the ui.Window class to manipulate windows as objects.
Forms define the layout and presentation of areas used by the program to display or input data. Typically, Forms are loaded by programs from external files with the 42f extension, the compiled version of Form Specification Files.
Forms files are identified by the file name, but you can also specify a form version with the VERSION attribute. The form version attribute is typically used to indicate that the form content has changed. The front-end is then able to distinguish different form versions and avoid saved settings to be reloaded on new form versions.
A program can load a Form file with the OPEN FORM instruction, then display the Form with DISPLAY FORM into the current window, and release resources with CLOSE FORM. However, it is recommended that you dedicate a window for each form. Programs typically create the window and load the form in a unique instruction: OPEN WINDOW WITH FORM.
When a Form is displayed, it is attached to the current window and a ui.Form object is created internally. You can get this object with the ui.Window.getForm() method. The ui.Form built-in class is provided to handle form elements. You can, for example, hide some parts of a form.
The Form that is used by interactive instructions like INPUT is defined by the current window.
Windows can be displayed in an MDI container application; see Dynamic User Interface for more details.
Creates and displays a new Window.
OPEN WINDOW identifier
[ AT line, column ]
WITH [ FORM form-file |
height ROWS, width COLUMNS ]
[ ATTRIBUTES ( window-attributes ) ]
An OPEN WINDOW statement can have the following effects:
The window identifier must follow the rules for identifiers and be unique among all windows defined in the program. Its scope is the entire program. You can use this identifier to reference the same Window in other modules with other statements (for example, CURRENT WINDOW and CLOSE WINDOW).
The runtime system maintains a stack of all open windows. If you execute OPEN WINDOW to open a new window, it is added to the window stack and becomes the current window. Other statements that can modify the window stack are CURRENT WINDOW and CLOSE WINDOW.
When using graphical mode, the WITH lines ROWS, characters COLUMNS clause is ignored, because the size of the window is automatically calculated according to its contents.
When using character mode, the WITH lines ROWS, characters COLUMNS clause specifies explicit vertical and horizontal dimensions for the window. The expression at the left of the ROWS keyword specifies the height of the window, in character unit lines. This must be an integer between 1 and max, where max is the maximum number of lines that the screen can display. The integer expression after the comma at the left of the COLUMNS keyword specifies the width of the window, in character unit columns. This must return a whole number between 1 and length, where length is the number of characters that your monitor can display on one line. In addition to the lines needed for a form, allow room for the Comment line, the Menu line, the Menu comment line and the Error line. The runtime system issues a runtime error if the window does not include sufficient lines to display both the form and these additional reserved lines. The minimum number of lines required to display a form in a window is the number of lines in the form, plus an additional line below the form for prompts, messages, and comments.
As an alternative to specifying explicit dimensions, the WITH FORM clause can specify a quoted string or a character variable that specifies the name of a file that contains the compiled screen form. The runtime system expects the compiled version of the form, but the file name should not include the .42f file extension. A window is automatically opened and sized to the screen layout of the form. When using character mode, the width of the window is from the left-most character on the screen form (including leading blank spaces) to the right-most character on the screen form (truncating trailing blank spaces). The length of the window is calculated as (form line) + (form length).
It is recommended that you use the WITH FORM clause, especially in the standard graphical mode, because the window is created in accordance with the form. If you use this clause, you do not need the OPEN FORM, DISPLAY FORM, or CLOSE FORM statement to open and close the form. The CLOSE WINDOW statement closes the window and the form.
By default windows are displayed as normal application windows, but you can use the window style to show a window at the top of all other windows, as a "modal window".
The window style defines the type of the window (normal, modal) and its decoration, via a Presentation Style. The Presentation Style specifies a set of attributes in an external file (.4st).
The STYLE attribute can be used in the OPEN WINDOW instruction to define the default style for a Window, It is better, however, to specify the window style in the form file, with the WINDOWSTYLE attribute of the LAYOUT section. This avoids decoration-specific code in the programs.
The following standard window styles are defined in the default presentation style file (FGLDIR/lib/default.4st):
STYLE attribute | Style name in 4st file | Description |
none | Window | Defines presentation attributes for common application windows. When using MDI containers, normal windows are displayed as MDI children. |
dialog | Window.dialog | Defines presentation attributes for typical OK/Cancel modal windows. |
naked | Window.naked | Defines presentation attributes for windows that should not show the default view for ring menus and action buttons (OK/Cancel). |
main | Window.main | Defines presentation attributes for starter applications, where the main window shows a startmenu if one is defined by the application. |
viewer | Window.viewer | Defines presentation attributes for viewers such as the report pager (fglreport.per). |
For more details about the attributes you can set for Windows, see Presentation Styles.
The TEXT attribute in the ATTRIBUTES clause defines the default title of the window. If the window is opened with a form (WITH FORM) that defines a TEXT attribute in the LAYOUT section, the default is ignored. Subsequent OPEN FORM instructions may change the window title if the form defines a new title in the LAYOUT section.
It is recommended that you specify the window title in the form file, not with the TEXT attribute of the OPEN WINDOW instruction.
If you want to set a window title dynamically, you can use the Window built-in class.
The following table shows the window-attributes supported by the OPEN WINDOW statement:
Attribute | Description |
TEXT = string | Defines the default title of the window. When a form is displayed, the
form title (LAYOUT(TEXT="mytitle")) will be used as the
window title. We recommend you define the window title in the form file! |
STYLE = string | Defines the default style of the window. If the form defines a window style, (LAYOUT(WINDOWSTYLE="mystyle")),
it overwrites the default window style. See Window Styles for more details. We recommend you define the window style in the form file! |
PROMPT LINE integer Console Only! |
In character mode, indicates the position of the prompt line for this window. The position can be specified with FIRST and LAST predefined line positions. |
FORM LINE integer Console Only! |
In character mode, indicates the position of the form line for this window. The position can be specified with FIRST and LAST predefined line positions. |
MENU LINE integer Console Only! |
In character mode, indicates the position of the ring menu line for this window. The position can be specified with FIRST and LAST predefined line positions. |
MESSAGE LINE integer Console Only! |
In character mode, indicates the position of the message line for this window. The position can be specified with FIRST and LAST predefined line positions. |
ERROR LINE integer Console Only! |
In character mode, indicates the position of the error line for this window. The position can be specified with FIRST and LAST predefined line positions. |
COMMENT LINE {OFF|integer} Console Only! |
In character mode, indicates the position of the comment line or no comment line at all, for this window. The position can be specified with FIRST and LAST predefined line positions. |
BORDER Console Only! |
Indicates whether the window must be created with a border in character mode. A border frame is drawn outside the specified window. This means that the window needs 2 additional lines and columns on the screen. |
BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW Console Only! |
Default color of the data displayed in the window. |
BOLD, DIM, INVISIBLE, NORMAL Console Only! |
Default font attribute of the data displayed in the window. |
REVERSE, BLINK, UNDERLINE Console Only! |
Default video attribute of the data displayed in the window. |
The following list describes the default line positions in character mode:
01
MAIN02
OPEN WINDOW w1 WITH FORM "customer"03
MENU "Test"04
COMMAND KEY(INTERRUPT) "exit" EXIT MENU05
END MENU06
CLOSE WINDOW w107
END MAIN
Closes and destroys a window.
CLOSE WINDOW identifier
01
MAIN02
OPEN WINDOW w1 WITH FORM "customer"03
MENU "Test"04
COMMAND KEY(INTERRUPT) "exit" EXIT MENU05
END MENU06
CLOSE WINDOW w107
END MAIN
In typical graphical applications, windows can be closed by the user, for example on Microsoft Windows by
pressing ALT+F4
or by clicking the cross button in the upper-left
corner of the window.
A Predefined Action is dedicated to this specific event: When the user closes a graphical window, the program gets a 'close' action.
By default, when the program is in a MENU instruction, the 'close' action is converted to an INTERRUPT key press (the key that cancels a dialog). This means that a COMMAND KEY(INTERRUPT) block is invoked if it is defined in the MENU statement. If there is no COMMAND KEY(INTERRUPT), nothing happens.
When the program is in an INPUT, INPUT ARRAY, CONSTRUCT or DISPLAY ARRAY, the 'close' action acts by default the same as the 'cancel' predefined action. So when the user clicks the X cross button, the dialog stops and int_flag is set to 1.
To prevent / overwrite the default behavior, you can overwrite the 'close' action as in the following example:
01
MAIN02
OPEN WINDOW w1 WITH FORM "customer"03
MENU "Test"04
ON ACTION quit05
DISPLAY "quit ..."06
EXIT MENU07
ON ACTION close08
DISPLAY "close ..."09
EXIT MENU10
END MENU11
CLOSE WINDOW w112
END MAIN
Make a specified window the current window.
CURRENT WINDOW IS identifier
Programs with multiple windows might need to switch to a different open window so that input and output occur in the appropriate window. To make a window the current window, use the CURRENT WINDOW statement.
When a program starts, the screen is the current window. Its name is SCREEN. To make this the current window, specify the keyword SCREEN instead of a window identifier.
If the window contains a form, that form becomes the current form when a CURRENT WINDOW statement specifies the name of that window. The CONSTRUCT, DISPLAY ARRAY, INPUT, INPUT ARRAY, and MENU statements use only the current window for input and output. If the user displays another form (for example, through an ON KEY clause) in one of these statements, the window containing the new form becomes the current window. When the CONSTRUCT, DISPLAY ARRAY, INPUT, INPUT ARRAY, or MENU statement resumes, its original window becomes the current window.
01
MAIN02
OPEN WINDOW w1 WITH FORM "customer"03
OPEN WINDOW w2 WITH FORM "custlist"04
MENU "Test"05
COMMAND "Win1"06
CURRENT WINDOW IS w107
COMMAND "Win2"08
CURRENT WINDOW IS w209
COMMAND KEY(INTERRUPT) "exit"10
EXIT MENU11
END MENU12
CLOSE WINDOW w113
CLOSE WINDOW w214
END MAIN
Clears the contents of a window in character mode.
CLEAR WINDOW identifier
Declares a compiled form in the program.
OPEN FORM identifier FROM file-name
In order to use a 42f compiled version of a Form Specification File, the programs must declare the form with the OPEN FORM instruction and then display the form in the current window by using the DISPLAY FORM instruction. Both operations can be automatically performed by opening a window that directly uses the form, using the WITH FORM clause:
01
OPEN WINDOW w1 WITH FORM "customer"
If you execute an OPEN FORM with the name of an open form, the runtime system first closes the existing form before opening the new form.
In character mode, the form is displayed in the current window at the position defined by the FORM LINE attribute, which can be specified in the ATTRIBUTE clause of OPEN WINDOW or as the default with the OPTIONS instruction.
After the form is loaded, you can activate the form by executing a CONSTRUCT, DISPLAY ARRAY, INPUT, or INPUT ARRAY statement. When the runtime system executes the OPEN FORM instruction, it allocates resources and loads the form into memory. To release the allocated resources when the form is no longer needed, the program must execute the CLOSE FORM instruction. This is a memory-management feature to recover memory from forms that the program no longer displays on the screen. If the form was loaded with a window by using the WITH FORM clause, it is automatically closed when the window is closed with a CLOSE WINDOW instruction.
The quoted string that follows the FROM keyword must specify the name of the file that contains the compiled screen form. This filename can include a pathname, but this is not recommended.
The form identifier does not need to match the name of the Form Specification File, but it must be unique among form names in the program. Its scope of reference is the entire program.
01
MAIN02
OPEN WINDOW w1 WITH 11 ROWS, 63 COLUMNS03
OPEN FORM f1 FROM "customer"04
DISPLAY FORM f105
CALL input_customer()06
CLOSE FORM f107
OPEN FORM f2 FROM "custlist"08
DISPLAY FORM f209
CALL input_custlist()10
CLOSE FORM f211
CLOSE WINDOW w112
END MAIN
Displays and associates a form with the current window.
DISPLAY FORM identifier
[ ATTRIBUTES ( display-attributes ) ]
The following table shows the display-attributes supported by the DISPLAY FORM statement:
Attribute | Description |
BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW | Default color of the data displayed in the form. |
BOLD, DIM, INVISIBLE, NORMAL | Default font attribute of the data displayed in the form. Warning: The INVISIBLE attribute is ignored. |
REVERSE, BLINK, UNDERLINE | Default video attribute of the data displayed in the form. |
The runtime system applies any other display attributes that you specify in the ATTRIBUTE clause to any fields that have not been assigned attributes by the ATTRIBUTES section of the Form Specification File, or by the database schema files, or by the OPTIONS statement. If the form is displayed in a window, color attributes from the DISPLAY FORM statement supersede any from the OPEN WINDOW statement. If subsequent CONSTRUCT, DISPLAY, or DISPLAY ARRAY statements that include an ATTRIBUTE clause reference the form, however, their attributes take precedence over those specified in the DISPLAY FORM instruction.
Closes a form.
CLOSE FORM identifier
Clears the complete application screen in character mode.
CLEAR SCREEN
Displays text at a given position in character mode in the current window.
DISPLAY text AT line, column [ ATTRIBUTE ( display-attributes
) ]
The following table shows the display-attributes supported by the DISPLAY AT statement:
Attribute | Description |
BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW Console Only! |
The color of the displayed text. |
BOLD, DIM, INVISIBLE, NORMAL Console Only! |
The font attribute of the displayed text. |
REVERSE, BLINK, UNDERLINE Console Only! |
The video attribute of the displayed text. |