Back to Contents


The Window class

Summary:

See also: Classes and Objects, Windows and Forms, Form Class


Syntax

The Window class is a built-in class providing an interface to the window objects.

Syntax:

ui.Window

Methods:

Class Methods
Name Description
forName( name STRING )
  RETURNING ui.Window
Returns a Window object according to the name used in an OPEN WINDOW statement.
getCurrent()
  RETURNING ui.Window
Returns a Window object referencing the current window.
Object Methods
Name Description
findNode( t STRING, n STRING )
  RETURNING om.DomNode
Returns the first descendant DOM node of type t and matching the name n in the abstract representation of this form object.
createForm( n STRING )
  RETURNING ui.Form
Creates an empty form and returns the new Form object.
getForm()
  RETURNING ui.Form
Returns a Form object to handle the current form.
getNode()
  RETURNING om.DomNode
Returns the DOM representation of this Window.
setText( t STRING ) Sets the title of this window object.
getText()
  RETURNING STRING
Returns the title of this window object.
setImage( n STRING ) Sets the image for the icon of this window object.
getImage()
  RETURNING STRING
Returns the icon image of this window object.

Usage:

Windows are created with the OPEN WINDOW instruction, identifying the window by a static handle:

01 OPEN WINDOW w1 WITH FORM "customer"

Getting a window object by name

You can get the window object corresponding to an identifier used in OPEN WINDOW with the ui.Window.forName() class method. You must declare a variable of type ui.Window to hold the window object reference:

01 DEFINE w ui.Window
02 LET w = ui.Window.forName("w1")

Getting the current window object

The ui.Window.getCurrent() class method returns a window object corresponding to the current window. You must declare a variable of type ui.Window to hold the window object reference:

01 DEFINE w ui.Window
02 LET w = ui.Window.getCurrent()

Getting the current form of a window

You can get a ui.Form instance of the current form with the getForm() method. This allows you to manipulate form elements by program. You can, for example, hide some parts of a form with setElementHidden().

Getting the DOM node of a window

The getNode() method returns the DOM node containing the abstract representation of the window.

Search for a specific element in the window

The findNode() method allows you to search for a specific DOM node in the abstract representation of the window content (i.e. the form). You search for a child node by giving its type and the name of the element (i.e. the tagname and the value of the 'name' attribute).

Create a new empty form in a window

The createForm() method can be used to create a new empty form. The method returns a new ui.Form instance or NULL if the form name passed as the parameter identifies an existing form used by the window.

Setting the window title

Use the setText() method to define the title of the window. By default, the title of a window is defined by the TEXT attribute of the LAYOUT definition in form files.

Getting the window title

The getText() method can be used to get the current title of a window.

Setting the window icon

Use the setImage() method to define the image to be used for the icon of the window. By default, the icon image of a window is defined by the IMAGE attribute of the LAYOUT definition in form files.

Getting the window icon

The getImage() method can be used to get the current icon image of a window.


Examples

Example 1: Get a window by name and change the title.

01 MAIN
02    DEFINE w ui.Window
03    OPEN WINDOW w1 WITH FORM "customer" ATTRIBUTE(TEXT="Unknown")
04    LET w = ui.Window.forName("w1")
05    IF w IS NULL THEN EXIT PROGRAM 1 END IF
06    CALL w.setText("Customer")
07    MENU "Test"
08      COMMAND "exit" EXIT MENU
09    END MENU
10    CLOSE WINDOW w1
11 END MAIN

Example 2: Get a the current form and hide a groupbox.

01 MAIN
02    DEFINE w ui.Window
03    DEFINE f ui.Form
04    OPEN WINDOW w1 WITH FORM "customer"
05    LET w = ui.Window.getCurrent()
06    IF w IS NULL THEN EXIT PROGRAM 1 END IF
07    LET f = w.getForm()
08    MENU "Test"
09       COMMAND "hide" CALL f.setElementHidden("gb1",1)
10       COMMAND "exit" EXIT MENU
11    END MENU
12    CLOSE WINDOW w1
13 END MAIN