SIMPOL Documentation

wxform

In both the wxwindow and wxdialog types, the content is provided by the wxform type. The same form can be used in a window, a dialog, or even a toolbar (though the form should be sized and shaped appropriately). To place a form into a window or dialog, call the setcontainer() method of the wxform object passing the target window or dialog object. The form contains a ring of graphics and a ring of controls. Graphical elements are added to the form using the addgraphic() method of the wxform type. Controls are added using the addcontrol() method of the wxform type. The list of graphical elements supported includes:

  • wxgraphicline

  • wxgraphicrectangle

  • wxgraphictriangle

  • wxgraphicarc

  • wxgraphicellipse

All of the above are type tagged as wxgraphic. This allows a variable that has been declared as type(wxgraphic) g to then contain a reference to any of the wxgraphic types. Graphical elements are always located behind controls. There is no method that can be used to cause them to be rendered in front of controls. The list of form controls currently provided is:

  • wxformbitmap

  • wxformbitmapbutton

  • wxformbutton

  • wxformcheckbox

  • wxformcombo

  • wxformedittext

  • wxformgrid

  • wxformlist

  • wxformoption

  • wxformscrollbar

  • wxformsizebox

  • wxformtext

All of these controls are type tagged as wxformcontrol, and therefore any variable declared as type(wxformcontrol) c can contain a reference to any of the form control types.

[Note]Note

The wxformoption type has a basic problem. It does not automatically come with any method of treating several of these buttons as a group. To overcome this, a solution was created and was placed in the sbnglib.sml library. This solution is based on the types:

  • wxformoptiongroup

  • wxformoptiongroupmember

To use it, create a wxformoptiongroup object. Then after creating each button, use the addmember() method of the option group object to add it to the group. If you intend to assign an onchange event to the option button, do this first, since otherwise things won't work (when the option button is added to the group, its onchange event information is replace with that of the group, and the old information is stored so that it can be called later).

Iterating Through wxform Elements

Earlier it was said that the form controls and graphics are in a ring. A ring is a specific type of data structure. The supplied SIMPOL language library called lists.sml provides implementations of singly-linked lists and rings, and doubly-linked lists and rings, as well as a queue and a stack. It is also supplied in source code as the lists project in the simpol\projects\libs directory. The way this works is that a reference to the first control on the form is assigned to the wxform.firstcontrol property. The same is true of the first graphic. A reference to it is assigned to the wxform.firstgraphic property. Each control or graphic also has a property called next, which is a reference to the next graphic or control. The next property of the final control or graphic on the form will refer to the first one, thus creating the ring. If there is only one control or graphic on the form, then its next property will refer to itself. Below is a function that takes a wform type as a parameter and then returns an array of all the control names. It could just as easily use the same technique to change the colors of all the controls, or resize, them, etc.

Example 22.1. Iterating Through Form Controls
function getcontrolnames(wxform f)
  type(wxformcontrol) c
  array names
  integer i

  i = 0
  names =@ array.new()
  if f !@= .nul
    c =@ f.firstcontrol
    while c !@= .nul
      i = i + 1
      names[i] = c.name
      c =@ c.next
    end while c =@= f.firstcontrol
  end if
end function names
            

The same approach could be used for graphical elements.

When to Use wxform

Generally the wxform and its associated controls are a good choice for forms that will not have data directly associated with the controls. Utility programs are a good example, as are basic dialogs that just retrieve some user choices and then process the results.