1.39 class dialog

A dialog is a window that is designed to be used for creating dialog boxes. A dialog performs automatic layout over its contents, thus largely simplifying the definition of simple dialog windows and the automatic generation of dialog windows.

Dialog windows normally only display instances of subclasses of class dialog_item. These are added to the dialog using the dialog->append method rather than device->display. dialog->append places the item relative to the other items in the dialog. When the frame in which the dialog resides is created, the final positions are automatically calculated by dialog->layout.

Dialog windows may be operated in two modes: each change to an item in the dialog immediately sends a message or pressing an apply button will apply all modifications made to the dialog. The example below illustrates a dialog of the latter type for editing some window attributes:

dialog(W) :-
        new(D, dialog('Edit Window Attributes')),
        send(D, append, label(reporter)),
        send(D, append,
             text_item(frame_label,
                       W?frame?label,
                       message(W?frame, label, @arg1))),
        send(D, append,
             slider(width, 50, 500, W?visible?width,
                            message(W, width, @arg1))),
        send(D, append,
             slider(height, 50, 500, W?visible?height,
                            message(W, height, @arg1))),
        send(D, append, button(apply)),
        send(D, append, button(restore)),
        send(D, append, button(quit, message(D, destroy))),
        send(D, default_button, apply),
        send(D, open).

?- new(@w, window),
     send(@w, open),
     dialog(@w).

This dialog may be converted into an immediate changing dialog by deleting the apply button. See dialog->apply, dialog->modified_item and dialog->restore for details.

See also
class dialog_item

1.39.1 Instance variables

dialog <-> border: [size]
Free area around contents. If not specified this is the same as dialog<-gap, the distance between items.
dialog -> gap: size
@see dialog->layout
dialog-size_given: {none,width,height,both}
Set by dialog->size, dialog->width and dialog->height. Used by dialog->_compute_desired_size to determine the dimensions that should not be altered. Values:
none
dialog->_compute_desired_size sets graphical<-width and graphical<-height.
width
dialog->_compute_desired_size only sets graphical<-width
height
dialog->_compute_desired_size only sets graphical<-height
both
dialog->_compute_desired_size does not modify dimensions.

1.39.2 Send methods

dialog ->_compute_desired_size:
This method is normally called from frame->fit. It invokes the automatic dialog->layout, assigns the dialog->caret to the first text_item and (depending on -size_given) computes the desired dimensions of the dialog window.
See also
- frame->fit
- dialog->layout
dialog ->active: bool
Inherits description from: dialog<-active
dialog ->append: item=graphical, relative_to_last=[{below,right,next_row}]
Append an instance of class dialog_item or a plain graphical object to the dialog object. The appended item is placed according to relative_to_last:
belowbelow the last one
rightright of the last one
next_rowbelow the left-most item of previous row

If relative_to_last is omitted, the following defaults apply: if the last item and this item are instances of class button, the item is placed right. Otherwise the item is placed next_row.

See also
- dialog->layout
- dialog->display
dialog ->apply: always=[bool]
Invoke the dialog_item<-message for each of the dialog_item's in device<-graphicals. If always equals @on the message will be invoked regardless whether the user has modified the item or not. If always equals @off or @default the message will only be invoked if dialog_item<-modified yields @on. If the dialog has a device<-default_button, execute graphical->active.

See also dialog->restore.

dialog ->assign_accelerators:
Assign accelerators for the dialog_item objects. This method collects the labels of all member device<-graphicals, computes a set of accelerators to use for them and finally uses dialog_item->accelerator to assign them.

See also menu->assign_accelerators and dialog->assign_accelerators.

dialog ->caret: member:graphical
Assign the caret to the named text_item object. See also device->advance and text_item<-advance.
dialog ->default_button: member:button*
Inherits description from: device<-default_button
dialog ->display: graphical, at=[point]
Display a graphical or dialog_item on a fixes position rather than exploiting automatic layout. Equivalent to device->display, but invokes
`dialog_item ->auto_align: @off`

To inform dialog->layout not to move this object.

See also
dialog->append
dialog ->initialise: label=[name], size=[size], display=[display]
Create an empty dialog window. After creation it is normal to display instances of class dialog_item in the dialog using dialog->append.
dialog ->layout: size=[size]
Align the dialog_item objects in the dialog. This method is normally called from dialog->_compute_desired_size when then dialog's frame is created. See also frame->fit.

The layout process consists of the following stages:

  1. Place all items for which dialog_item<-auto_align in a two-dimensional grid.
  2. Automatically align labels and values of items placed above each other depending on dialog_item<-auto_label_align, dialog_item<-label_width, dialog_item<-auto_value_align and dialog_item<-value_width
  3. Items that have dialog_item<-alignment not column, but one of left, center or right are not horizontally with items above or below them, but combined with items to their left and right into sequences of items with the same alignment. At the end of the layout process aligned such sequences are aligned in the available space. Notably button objects have dialog_item<-alignment, so a row of buttons is normally centered in the dialog window.
  4. Compute the cell-size of the matrix and align the dialog_item<-reference in the two-dimensional grid.
    See also
    - dialog_item-placed
    - dialog_item-left
    - dialog_item-label_width
    - dialog_item-below
    - dialog_item-auto_value_align
    - dialog_item-auto_label_align
    - dialog_item-align_in_column
    - dialog_item-above
    - dialog->_compute_desired_size
    - dialog->append
    - dialog-gap
    - class dialog_item
dialog ->modified_item: item=graphical, modified=bool
This message is normally invoked by one of the member dialog_item objects. If the dialog has a device<-default_button, this button will be activated using graphical->active. Otherwise, this method fails. Dialog-items will send their dialog_item<-message immediately if this message fails. Otherwise they assume the default button will activate dialog->apply.

See also dialog_item->modified, dialog->apply and dialog->restore.

dialog ->restore:
Restores all items in the dialog to their default state by invoking graphical->restore to all device<-graphicals. If the dialog has a device<-default_button, this is send graphical->active.

See also graphical->restore, dialog_item<-default and dialog_item->modified, graphical->apply and dialog->apply.

dialog ->size: size
Set the size of the window as graphical->size and sets -size_given to both to avoid overruling of the given size by the automatic layout system invoked by dialog->_compute_desired_size. See also dialog->width and dialog->height
dialog ->height: 0..
Give dialog an explicit height.
dialog ->width: 0..
Defines the width of the dialog window. If dialog->_compute_desired_size computes the size on the basis of the dialog's contents, the graphical<-width will not be changed after this message. Sets -size_given to width or both. See also dialog->height and dialog->size.

1.39.3 Get methods

dialog <-active: -> bool
Equivalent to window<->sensitive. Both for consistency with class dialog_item and for backward compatibility.
dialog <-border: -> size
If the object<-slot -border is not @default return it, else return dialog<-gap.
device <-default_button: -> button
The default window of a dialog window is the button that has accelerator RET. There is no default default_button. See also dialog->modified_item and dialog->apply.
dialog <-report_to: -> graphical|frame
If there is a dialog<-member dialog_item called reporter, this item is returned. Otherwise visual<-report_to is invoked.

This method is normally exploited by displaying a label object with name reporter on the dialog object. This label will then display all error messages raised from operating the dialog item. See visual->report, object->report and class error.

See also
- visual<-report_to
- label->report