# 6 Standard dialog boxes

QTk offers the following standard dialog boxes:

- Save file selection

- Load file selection

- Color selection

- Canvas print parameters

If the application runs on a Windows platform, the first 3 dialog boxes are the standard one from Windows.

## 6.1 Save and load dialog boxes

The save and load dialog boxes are spawned by:

> `{QTk.dialogbox save(defaultextension:DE
> filetypes:FT
> initialdir:ID
> initialfile:IF
> title:Title
> 1:R)}`

and

> `{QTk.dialogbox load(defaultextension:DE
> filetypes:FT
> initialdir:ID
> initialfile:IF
> title:Title
> 1:R)}`

Example:

> `Result={QTk.dialogbox load(defaultextension:"qdw"
> initialdir:"."
> title:"Load QTkDrawing..."
> initialfile:""
> filetypes:q(q("QTkDraw files" q(".qdw"))
> q("All files" q("*"))) $)}`

The parameters are:

- `defaultextension`: a virtual string specifying the default extension for the file if the user doesn't type one. If not specified, an empty string is assumed.

- `filetypes`: a record of the form `q(R1 .. Rx)` where `Ri` are records of the form `q(TextDesc q(Extension1 .. Extensiony)` with `TextDesc` and `Extensioni` virtual strings. This parameter specifies different filters for displaying files. Each `Ri` specifies one filter, `TextDesc` being the textual description shown to the user. Each `Extensioni` specifies an extension valid for this filter. If not specified, `q("All files" q("*"))` is assumed.

- `initialdir`: a virtual string specifying the initial directory. If not specified, `"."` is assumed.

- `initialfile`: a virtual string specifying a default file name. If not specified, an empty string is assumed.

- `title`: a virtual string specifying the title of the dialog box. If not specified, `"Open"` or `"Save"` are assumed.

- `1`: a free variable that is bound to the filename selected by the user or to `nil` if he cancelled.

## 6.2 Color dialog box

The color dialog box is spawned by:

> `{QTk.dialogbox color(initialcolor:IC
> title:Title
> 1:R)}`

Example:

> `Result={QTk.dialogbox color(initialcolor:c(255 0 0)
> title:"Select a color..." $)}`

The parameters are:

- `initialcolor`: the initial color (see Section 8.2). If not specified, a random color is picked by default.

- `title`: a virtual string specifying the title of the dialog box. If not specified, `"Color"` is assumed.

- `1`: a free variable that is bound to the filename selected by the user or to `nil` if he cancelled.

## 6.3 Print Canvas dialog box

Canvases can be printed by their `postscript` method. The print canvas dialog box can be used to let the user interactively specify all the parameters of this method. To help the user correctly choose the area to print, a rough copy of the canvas is done inside the dialog box.

The print canvas dialog box is spawned by:

> `{QTk.dialogbox printcanvas(canvas:C
> title:Title
> region:R
> zoom:Z
> rotate:R
> fit:F
> pagewidth:PW
> pageheight:PH
> pagex:PX
> pagey:PY
> width:W
> height:H
> colormode:CM
> x:X
> y:Y
> 1:R)}`

Example:

> `C
> {{QTk.build td(canvas(glue:nswe handle:C))} show}
> {C create(rectangle 10 10 100 100)}
> Result={QTk.dialogbox printcanvas(canvas:C $)}
> {C postscript(colormode:Result.colormode
> pagewidth:Result.pagewidth
> pagex:0.0
> pagey:0.0
> pageanchor:sw
> rotate:Result.rotate
> width:Result.tkwidth
> height:Result.tkheight
> x:Result.tkx
> y:Result.tky
> file:"out.ps")`

The parameters are:

- `canvas`: the handle of the canvas to print.

- `title`: a virtual string specifying the title of the dialog box. If not specified, `"Postscript Generation Options"` is assumed.

- `region`: a list of 4 integers `[X Y Width Height]` specifying the region of the canvas that is printable. `X` and `Y` is the coordinate of the top-left corner, and `Width` and `Height` the width and height of this area. If not specified, `[0 0 200 200]` is assumed.

- `zoom`: a real specifying a zoom factor to apply to the area to print. If not specified, `1.0` is assumed.

- `rotate`: a boolean specifying the canvas must be rotated 90 degrees when printed or not. If not specified, `false` is assumed.

- `fit`: a boolean specifying if the area to print must be stretched to fit the whole page or not. If not specified, `false` is assumed.

- `pagewidth`: a virtual string representing the page width. Valid strings are composed of an integer value followed by one of these letters: `c`, `m`, `i`, `p`. `c` stands for centimers, `m` for millimeters, `i` for inches and `p` for picas. If not specified, the string `"210m"` is assumed.

- `pageheight`: a virtual string representing the page height. Valid strings are valid strings for the `pagewidth` parameter. If not specified, the string `"297m"` is assumed.

- `pagex`: a virtual string representing the left margin of the page. Valid strings are valid strings for the `pagewidth` parameter. If not specified, the string `"10m"` is assumed.

- `pagey`: a virtual string representing the top margin of the page. Valid strings are valid strings for the `pagewidth` parameter. If not specified, the string `"10m"` is assumed.

- `width`: an integer specifying the width of the area of the canvas to print. If not specified, the horizontal space available from the print region of the canvas is assumed.

- `height`: an integer specifying the height of the area of the canvas to print. If not specified, the vertical space available from the print region of the canvas is assumed.

- `colormode`: an atom specifying if the page must be printed in color, shades of gray or pure black and white. Valid values are `color`, `gray` and `mono`. If not specified, `mono` is assumed.

- `x`: an integer specifying the horizontal origin of the area of the canvas to print. If not specified, 0 is assumed.

- `y`: an integer specifying the horizontal origin of the area of the canvas to print. If not specified, 0 is assumed.

- `1`: a free variable that is bound to `nil` if the user cancelled, or that is bound to a record containing a feature for each parameter described here. Note that the semantics of the parameters `width`, `height`, `x` and `y` are slightly different from those of the `postscript` method of canvases. Consequently, the returned record of `printcanvas` also has the features `tkwidth`, `tkheight`, `tkx` and `tky` that contain the values that should be given to the `width`, `height`, `x` and `y` parameters of the `postscript` method of canvases (see example).