<CHAPTER ID="chapter.stddialog">
  <TITLE>Standard dialog boxes</TITLE>
<p>
QTk offers the following standard dialog boxes:
<list>
<item> Save file selection
<item> Load file selection
<item> Color selection
<item> Canvas print parameters
</list>
If the application runs on a Windows platform, the first 3 dialog boxes are the standard one from Windows.

<section><title>Save and load dialog boxes</title>
<p>
<picture.extern to="load.gif" type=gif>
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:
<list>
<item> <<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.
<item> <<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.
<item> <<initialdir>>: a virtual string specifying the initial directory. If not specified, <<".">> is assumed.
<item> <<initialfile>>: a virtual string specifying a default file name. If not specified, an empty string is assumed.
<item> <<title>>: a virtual string specifying the title of the dialog box. If not specified, <<"Open">> or <<"Save">> are assumed.
<item> <<1>>: a free variable that is bound to the filename selected by the user or to <<nil>> if he cancelled.
</list>
<section><title>Color dialog box</title>
<p>
<picture.extern to="color.gif" type=gif>
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:
<list>
<item> <<initialcolor>>: the initial color (see <ptr to="misc.color">). If not specified, a random color is picked by default.
<item> <<title>>: a virtual string specifying the title of the dialog box. If not specified, <<"Color">> is assumed.
<item> <<1>>: a free variable that is bound to the filename selected by the user or to <<nil>> if he cancelled.
</list>
<section><title>Print Canvas dialog box</title>
<p>
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.</p>
<p>
<picture.extern to="printcanvas.gif" type=gif>
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:
<list>
<item> <<canvas>>: the handle of the canvas to print.
<item> <<title>>: a virtual string specifying the title of the dialog box. If not specified, <<"Postscript Generation Options">> is assumed.
<item> <<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.
<item> <<zoom>>: a real specifying a zoom factor to apply to the area to print. If not specified, <<1.0>> is assumed.
<item> <<rotate>>: a boolean specifying the canvas must be rotated 90 degrees when printed or not. If not specified, <<false>> is assumed.
<item> <<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.
<item> <<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.
<item> <<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.
<item> <<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.
<item> <<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.
<item> <<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.
<item> <<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.
<item> <<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.
<item> <<x>>:  an integer specifying the horizontal origin of the area of the canvas to print. If not specified, 0 is assumed.
<item> <<y>>:  an integer specifying the horizontal origin of the area of the canvas to print. If not specified, 0 is assumed.
<item> <<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).
</list>


</CHAPTER>
